static void on( const undelegatebw& del ) { eosio_assert( del.unstake_cpu_quantity.quantity >= 0, "must stake a positive amount" ); eosio_assert( del.unstake_net_quantity.quantity >= 0, "must stake a positive amount" ); auto total_stake = del.unstake_cpu_quantity + del.unstake_net_quantity; eosio_assert( total_stake.quantity >= 0, "must stake a positive amount" ); require_auth( del.from ); del_bandwidth_index_type del_index( SystemAccount, del.from ); total_resources_index_type total_index( SystemAccount, del.receiver ); //eosio_assert( is_account( del.receiver ), "can only delegate resources to an existing account" ); const auto& dbw = del_index.get(del.receiver); eosio_assert( dbw.net_weight >= del.unstake_net_quantity, "insufficient staked net bandwidth" ); eosio_assert( dbw.cpu_weight >= del.unstake_cpu_quantity, "insufficient staked cpu bandwidth" ); del_index.update( dbw, del.from, [&]( auto& dbo ){ dbo.net_weight -= del.unstake_net_quantity; dbo.cpu_weight -= del.unstake_cpu_quantity; }); const auto& totals = total_index.get( del.receiver ); total_index.update( totals, 0, [&]( auto& tot ) { tot.total_net_weight -= del.unstake_net_quantity; tot.total_cpu_weight -= del.unstake_cpu_quantity; }); set_resource_limits( totals.owner, totals.total_ram, totals.total_net_weight.quantity, totals.total_cpu_weight.quantity, 0 ); /// TODO: implement / enforce time delays on withdrawing currency::inline_transfer( SystemAccount, del.from, total_stake, "unstake bandwidth" ); } // undelegatebw
VOID del_objindex(LONG tree, WORD obj) { WORD where; where = find_obj(tree, obj); if (where != NIL) del_index(where); }
VOID get_obname(BYTE *name, LONG ntree, WORD nobj) { WORD where; LONG addr; addr = ntree + nobj * sizeof(OBJECT); where = find_value((BYTE *) addr); if (where != NIL) { if (!name[0] || name[0] == '@') del_index(where); else strcpy(get_name(where), name); } else { if (name[0] && name[0] != '@') { where = new_index((BYTE *)addr, OBJKIND, name); if (where == NIL) hndl_alert(1, string_addr(STNFULL)); } } }
void analyze_trace(const char *path) { struct btsnoop *btsnoop_file; unsigned long num_packets = 0; uint32_t type; btsnoop_file = btsnoop_open(path, BTSNOOP_FLAG_PKLG_SUPPORT); if (!btsnoop_file) return; type = btsnoop_get_type(btsnoop_file); switch (type) { case BTSNOOP_TYPE_HCI: case BTSNOOP_TYPE_UART: case BTSNOOP_TYPE_MONITOR: break; default: fprintf(stderr, "Unsupported packet format\n"); goto done; } dev_list = queue_new(); if (!dev_list) { fprintf(stderr, "Failed to allocate device list\n"); goto done; } while (1) { unsigned char buf[BTSNOOP_MAX_PACKET_SIZE]; struct timeval tv; uint16_t index, opcode, pktlen; if (!btsnoop_read_hci(btsnoop_file, &tv, &index, &opcode, buf, &pktlen)) break; switch (opcode) { case BTSNOOP_OPCODE_NEW_INDEX: new_index(&tv, index, buf, pktlen); break; case BTSNOOP_OPCODE_DEL_INDEX: del_index(&tv, index, buf, pktlen); break; case BTSNOOP_OPCODE_COMMAND_PKT: command_pkt(&tv, index, buf, pktlen); break; case BTSNOOP_OPCODE_EVENT_PKT: event_pkt(&tv, index, buf, pktlen); break; case BTSNOOP_OPCODE_ACL_TX_PKT: case BTSNOOP_OPCODE_ACL_RX_PKT: acl_pkt(&tv, index, buf, pktlen); break; case BTSNOOP_OPCODE_SCO_TX_PKT: case BTSNOOP_OPCODE_SCO_RX_PKT: sco_pkt(&tv, index, buf, pktlen); break; case BTSNOOP_OPCODE_OPEN_INDEX: case BTSNOOP_OPCODE_CLOSE_INDEX: break; default: fprintf(stderr, "Wrong opcode %u\n", opcode); goto done; } num_packets++; } printf("Trace contains %lu packets\n\n", num_packets); queue_destroy(dev_list, dev_destroy); done: btsnoop_unref(btsnoop_file); }
ACTION( SystemAccount, regproducer ) { account_name producer; bytes producer_key; EOSLIB_SERIALIZE( regproducer, (producer)(producer_key) ) }; ACTION( SystemAccount, regproxy ) { account_name proxy_to_register; EOSLIB_SERIALIZE( regproxy, (proxy_to_register) ) }; ACTION( SystemAccount, delegatebw ) { account_name from; account_name receiver; typename currency::token_type stake_net_quantity; typename currency::token_type stake_cpu_quantity; EOSLIB_SERIALIZE( delegatebw, (from)(receiver)(stake_net_quantity)(stake_cpu_quantity) ) }; ACTION( SystemAccount, undelegatebw ) { account_name from; account_name receiver; typename currency::token_type unstake_net_quantity; typename currency::token_type unstake_cpu_quantity; EOSLIB_SERIALIZE( undelegatebw, (from)(receiver)(unstake_net_quantity)(unstake_cpu_quantity) ) }; ACTION( SystemAccount, nonce ) { eosio::string value; EOSLIB_SERIALIZE( nonce, (value) ) }; /// new id options: // 1. hash + collision // 2. incrementing count (key=> tablename static void on( const delegatebw& del ) { eosio_assert( del.stake_cpu_quantity.quantity >= 0, "must stake a positive amount" ); eosio_assert( del.stake_net_quantity.quantity >= 0, "must stake a positive amount" ); auto total_stake = del.stake_cpu_quantity + del.stake_net_quantity; eosio_assert( total_stake.quantity >= 0, "must stake a positive amount" ); require_auth( del.from ); del_bandwidth_index_type del_index( SystemAccount, del.from ); total_resources_index_type total_index( SystemAccount, del.receiver ); //eosio_assert( is_account( del.receiver ), "can only delegate resources to an existing account" ); auto itr = del_index.find( del.receiver); if( itr != nullptr ) { del_index.emplace( del.from, [&]( auto& dbo ){ dbo.from = del.from; dbo.to = del.receiver; dbo.net_weight = del.stake_net_quantity; dbo.cpu_weight = del.stake_cpu_quantity; }); } else { del_index.update( *itr, del.from, [&]( auto& dbo ){ dbo.net_weight = del.stake_net_quantity; dbo.cpu_weight = del.stake_cpu_quantity; }); } auto tot_itr = total_index.find( del.receiver ); if( tot_itr == nullptr ) { tot_itr = &total_index.emplace( del.from, [&]( auto& tot ) { tot.owner = del.receiver; tot.total_net_weight += del.stake_net_quantity; tot.total_cpu_weight += del.stake_cpu_quantity; }); } else { total_index.update( *tot_itr, 0, [&]( auto& tot ) { tot.total_net_weight += del.stake_net_quantity; tot.total_cpu_weight += del.stake_cpu_quantity; }); } set_resource_limits( tot_itr->owner, tot_itr->total_ram, tot_itr->total_net_weight.quantity, tot_itr->total_cpu_weight.quantity, 0 ); currency::inline_transfer( del.from, SystemAccount, total_stake, "stake bandwidth" ); } // delegatebw