Skip to content

Commit fd8b367

Browse files
author
Stan Drozd
committed
pyth.cpp: upd_price takes price value, confidence and symbol status
1 parent b958865 commit fd8b367

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

pcapps/pyth.cpp

+86
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ int usage()
4949
std::cerr << " upd_product <product.json> [options]" << std::endl;
5050
std::cerr << " upd_price <price_key> [options]"
5151
<< std::endl;
52+
std::cerr << " upd_price_val <price_key> <value> <confidence> <status> [options]"
53+
<< std::endl;
5254
std::cerr << " upd_test <test_key> <test.json> [options]"
5355
<< std::endl;
5456
std::cerr << " get_balance [<pub_key>] [options]" << std::endl;
@@ -804,9 +806,12 @@ int on_upd_price( int argc, char **argv )
804806
if ( argc < 2 ) {
805807
return usage();
806808
}
809+
810+
// Price Key
807811
std::string pkey( argv[1] );
808812
pub_key pub;
809813
pub.init_from_text( pkey );
814+
810815
argc -= 1;
811816
argv += 1;
812817

@@ -866,6 +871,85 @@ int on_upd_price( int argc, char **argv )
866871
return 0;
867872
}
868873

874+
int on_upd_price_val( int argc, char **argv )
875+
{
876+
if ( argc < 5 ) {
877+
return usage();
878+
}
879+
880+
// Price Key
881+
std::string pkey( argv[1] );
882+
pub_key pub;
883+
pub.init_from_text( pkey );
884+
885+
// Price Value
886+
uint64_t price_value = atoll(argv[2]);
887+
888+
// Confidence
889+
uint64_t confidence = atoll(argv[3]);
890+
891+
// Status
892+
symbol_status price_status = str_to_symbol_status(argv[4]);
893+
894+
argc -= 4;
895+
argv += 4;
896+
897+
int opt = 0;
898+
commitment cmt = commitment::e_confirmed;
899+
std::string rpc_host = get_rpc_host();
900+
std::string tx_host = get_rpc_host();
901+
std::string key_dir = get_key_store();
902+
while( (opt = ::getopt(argc,argv, "r:t:k:c:dh" )) != -1 ) {
903+
switch(opt) {
904+
case 'r': rpc_host = optarg; break;
905+
case 't': tx_host = optarg; break;
906+
case 'k': key_dir = optarg; break;
907+
case 'd': log::set_level( PC_LOG_DBG_LVL ); break;
908+
case 'c': cmt = str_to_commitment(optarg); break;
909+
default: return usage();
910+
}
911+
}
912+
if ( cmt == commitment::e_unknown ) {
913+
std::cerr << "pyth: unknown commitment level" << std::endl;
914+
return usage();
915+
}
916+
917+
// initialize connection to block-chain
918+
manager mgr;
919+
mgr.set_rpc_host( rpc_host );
920+
mgr.set_tx_host( tx_host );
921+
mgr.set_dir( key_dir );
922+
mgr.set_do_tx( true );
923+
mgr.set_commitment( cmt );
924+
if ( !mgr.init() || !mgr.bootstrap() ) {
925+
std::cerr << "pyth: " << mgr.get_err_msg() << std::endl;
926+
return 1;
927+
}
928+
// get price and crank
929+
price *ptr = mgr.get_price( pub );
930+
if ( !ptr ) {
931+
std::cerr << "pyth: failed to find price key=" << pkey << std::endl;
932+
return 1;
933+
}
934+
if ( !ptr->has_publisher() ) {
935+
std::cerr << "pyth: missing publisher permission" << std::endl;
936+
return 1;
937+
}
938+
ptr->update(price_value, confidence, price_status);
939+
while( mgr.get_is_tx_send() && !mgr.get_is_err() ) {
940+
mgr.poll();
941+
}
942+
if ( ptr->get_is_err() ) {
943+
std::cerr << "pyth: " << ptr->get_err_msg() << std::endl;
944+
return 1;
945+
}
946+
if ( mgr.get_is_err() ) {
947+
std::cerr << "pyth: " << mgr.get_err_msg() << std::endl;
948+
return 1;
949+
}
950+
return 0;
951+
}
952+
869953
int on_upd_publisher( int argc, char **argv, bool is_add )
870954
{
871955
// get input parameters
@@ -1502,6 +1586,8 @@ int main(int argc, char **argv)
15021586
rc = on_upd_product( argc, argv );
15031587
} else if ( cmd == "upd_price" ) {
15041588
rc = on_upd_price( argc, argv );
1589+
} else if ( cmd == "upd_price_val" ) {
1590+
rc = on_upd_price_val( argc, argv );
15051591
} else if ( cmd == "upd_test" ) {
15061592
rc = on_upd_test( argc, argv );
15071593
} else if ( cmd == "get_pub_key" ) {

0 commit comments

Comments
 (0)