Esempio n. 1
0
 def execute(self, client, params, **kwargs):
     if len(params) < 4 or len(params) > 7:
         self.print_params_help()
         return
     if len(params) == 5:
         metadata = bytes.fromhex(params[4])
     else:
         metadata = b''
     if len(params) == 6:
         gas_unit_price_in_micro_libras = Uint64.int_safe(params[5])
     else:
         gas_unit_price_in_micro_libras = 0
     if len(params) == 7:
         max_gas_amount_in_micro_libras = Uint64.int_safe(params[6])
     else:
         max_gas_amount_in_micro_libras = 400_000
     print(">> Transferring")
     is_blocking = blocking_cmd(params[0])
     sequence_number = client.transfer_coins(
         params[1],
         params[2],
         params[3],
         max_gas_amount=max_gas_amount_in_micro_libras,
         gas_unit_price=gas_unit_price_in_micro_libras,
         is_blocking=is_blocking,
         metadata=metadata)
     if is_blocking:
         print("Finished transaction!")
     else:
         print("Transaction submitted to validator")
     print("To query for transaction status, run: query txn_acc_seq {} {} \
         <include_events=true|false>".format(params[1], sequence_number))
Esempio n. 2
0
 def execute(self, client, params, **kwargs):
     if len(params) < 4:
         include_events = True
     else:
         include_events = parse_bool(params[3])
     sn = client.get_transactions(Uint64.int_safe(params[1]),
                                  Uint64.int_safe(params[2]),
                                  include_events)
     json_print_in_cmd([x.to_json_serializable() for x in sn])
Esempio n. 3
0
 def get_events_by_account_and_type(self, address_or_refid, sent_received,
                                    start_seq, ascending, limit):
     address = self.parse_address_or_refid(address_or_refid)
     start_seq = Uint64.int_safe(start_seq)
     limit = Uint64.int_safe(limit)
     if sent_received == "sent":
         return self.grpc_client.get_events_sent(address, start_seq,
                                                 ascending, limit)
     elif sent_received == "received":
         return self.grpc_client.get_events_received(
             address, start_seq, ascending, limit)
     else:
         raise IOError(
             f"Unknown event type: {sent_received}, only sent and received are supported"
         )
Esempio n. 4
0
 def mint_coins(self, address_or_refid, libra, is_blocking):
     micro_libra = Uint64.int_safe(libra) * 1_000_000
     address, prefix = self.get_account_address_from_parameter(
         address_or_refid)
     self.grpc_client.mint_coins(address,
                                 prefix,
                                 micro_libra,
                                 is_blocking=is_blocking)
Esempio n. 5
0
 def transfer_coins(self, sender, recevier, coin, **kwargs):
     account = self.address_or_refid_to_account(sender)
     # TODO: do we really need auth_key_prefix for p2p transfer?
     recevier = self.parse_address_or_refid(recevier)
     micro_libra = Uint64.int_safe(coin) * 1_000_000
     self.grpc_client.transfer_coin(account, recevier, micro_libra,
                                    **kwargs)
     return account.sequence_number
Esempio n. 6
0
 def get_events(self, key, start_sequence_number, ascending=True, limit=1):
     limit = Uint64.int_safe(limit)
     if limit == 0:
         raise ValueError(f"limit:{limit} is invalid.")
     params = [key, start_sequence_number, limit]
     events = self.json_rpc("get_events", params)
     if not ascending:
         events = reversed(events)
     return [DictObj(ev) for ev in events]
Esempio n. 7
0
 def execute(self, client, params, **kwargs):
     is_blocking = blocking_cmd(params[0])
     wallet = WalletLibrary.recover(params[4])
     account = wallet.get_account_by_address_or_refid(params[1])
     resp = client.transfer_coin(account,
                                 params[2],
                                 Uint64.int_safe(params[3]),
                                 is_blocking=is_blocking)
     json_print_in_cmd(resp)
Esempio n. 8
0
 def execute(self, client, params, **kwargs):
     print(">> Getting committed transaction by range")
     include_events = parse_bool(params[3])
     transactions = client.get_committed_txn_by_range(
         params[1], params[2], include_events)
     cur_version = Uint64.int_safe(params[1])
     for index, signed_tx in enumerate(transactions):
         # TODO: events print
         print(f"Transaction at version {cur_version+index}: {signed_tx}")
Esempio n. 9
0
 def parse_address_or_refid(self, address_or_refid):
     if len(address_or_refid) == Address.LENGTH * 2:
         return address_or_refid
     else:
         idx = Uint64.int_safe(address_or_refid)
         if idx >= 0 and idx < self.wallet.child_count:
             return self.accounts[idx].address.hex()
         else:
             raise IOError(
                 f"account index {idx} out of range:{self.wallet.child_count}"
             )
Esempio n. 10
0
 def get_account_address_from_parameter(self, address_or_refid):
     if len(address_or_refid) == 64:
         return (address_or_refid[0:32], address_or_refid[0:32])
     elif len(address_or_refid) == Address.LENGTH * 2:
         raise "Need authentication key, not address."
     else:
         idx = Uint64.int_safe(address_or_refid)
         if idx >= 0 and idx < self.wallet.child_count:
             return (self.accounts[idx].address,
                     self.accounts[idx].auth_key_prefix)
         else:
             raise IOError(
                 f"account index {idx} out of range:{self.wallet.child_count}"
             )
Esempio n. 11
0
 def mint_coins_with_faucet_service(self,
                                    auth_key,
                                    micro_libra,
                                    is_blocking=False):
     if isinstance(auth_key, bytes):
         auth_key = auth_key.hex()
     params = {
         "amount": micro_libra,
         "auth_key": auth_key,
         "currency_code": "LBR",
     }
     resp = requests.post(self.faucet_host,
                          params=params,
                          timeout=self.timeout)
     if resp.status_code != 200:
         raise IOError(
             f"Faucet service {self.faucet_host} error: {resp.status_code}, {resp.text}"
         )
     sequence_number = Uint64.int_safe(resp.text) - 1
     if is_blocking:
         self.wait_for_transaction(
             AccountConfig.treasury_compliance_account_address(),
             sequence_number)
     return sequence_number
Esempio n. 12
0
 def get_committed_txn_by_range(self, start, limit, include_events):
     start = Uint64.int_safe(start)
     limit = Uint64.int_safe(limit)
     transactions = self.grpc_client.get_transactions(start, limit)
     return transactions
Esempio n. 13
0
 def get_committed_txn_by_acc_seq(self, address_or_refid, seq,
                                  include_events):
     address = self.parse_address_or_refid(address_or_refid)
     seq = Uint64.int_safe(seq)
     return self.grpc_client.get_account_transaction(
         address, seq, include_events)
Esempio n. 14
0
 def execute(self, client, params, **kwargs):
     is_blocking = blocking_cmd(params[0])
     resp = client.mint_coins(params[1], Uint64.int_safe(params[2]),
                              is_blocking)
     json_print_in_cmd({"sequence_number": resp})
Esempio n. 15
0
 def execute(self, client, params, **kwargs):
     include_events = parse_bool(params[3])
     seq = Uint64.int_safe(params[2])
     transaction = client.get_account_transaction(params[1], seq,
                                                  include_events)
     json_print_in_cmd(transaction)