예제 #1
0
 def from_proto(cls, proto):
     ret = cls()
     ret.signed_transaction_hash = bytes_to_int_list(
         proto.signed_transaction_hash)
     ret.state_root_hash = bytes_to_int_list(proto.state_root_hash)
     ret.event_root_hash = bytes_to_int_list(proto.event_root_hash)
     ret.gas_used = proto.gas_used
     ret.major_status = proto.major_status
     return ret
예제 #2
0
 def parse_as_transaction_argument(cls, s):
     address = parse_address(s)
     if address is not None:
         return TransactionArgument('Address', bytes_to_int_list(address))
     elif s[0:2] == 'b"' and s[-1] == '"' and len(s) > 3:
         barr = bytes.fromhex(s[2:-1])
         return TransactionArgument('ByteArray', bytes_to_int_list(barr))
     else:
         try:
             i = int(s)
             return TransactionArgument('U64', i)
         except Exception:
             raise
     raise TypeError(f"cannot parse {s} as transaction argument")
예제 #3
0
def test_equal_address():
    hexaddr = AccountConfig.association_address()
    bytesaddr = parse_address("0xa550c18")
    intsaddr = bytes_to_int_list(bytesaddr)
    assert Address.equal_address(hexaddr, bytesaddr)
    assert Address.equal_address(hexaddr, intsaddr)
    assert False == Address.equal_address(hexaddr, parse_address("0x123"))
예제 #4
0
 def gen_transfer_script(cls, receiver_address, micro_libra):
     if isinstance(receiver_address, bytes):
         receiver_address = bytes_to_int_list(receiver_address)
     if isinstance(receiver_address, str):
         receiver_address = hex_to_int_list(receiver_address)
     code = bytecodes["peer_to_peer_transfer"]
     args = [
         TransactionArgument('Address', receiver_address),
         TransactionArgument('U64', micro_libra)
     ]
     return Script(code, args)
예제 #5
0
def normalize_public_key(public_key):
    if isinstance(public_key, list):
        if len(public_key) != ED25519_PUBLIC_KEY_LENGTH:
            raise ValueError(f"{public_key} is not a valid public_key.")
        return public_key
    if isinstance(public_key, bytes):
        if len(public_key) != ED25519_PUBLIC_KEY_LENGTH:
            raise ValueError(f"{public_key} is not a valid public_key.")
        return bytes_to_int_list(public_key)
    if isinstance(public_key, str):
        if len(public_key) != ED25519_PUBLIC_KEY_LENGTH*2:
            raise ValueError(f"{public_key} is not a valid public_key.")
        return hex_to_int_list(public_key)
예제 #6
0
    def resource_access_vec(cls, tag, accesses):
        key = []
        key.append(cls.RESOURCE_TAG)
        key.extend(bytes_to_int_list(tag.hash()))
        #We don't need accesses in production right now. Accesses are appended here just for
        #passing the old tests.
        astr = Accesses.as_separated_string(accesses)
        key.extend(AccessPath.str_to_ints(astr))
        return key


# VALIDATOR_SET_ACCESS_PATH = AccessPath(
#     hex_to_int_list(AccountConfig.association_address()),
#     ValidatorSet.validator_set_path()
# )
예제 #7
0
 def gen_from_raw_txn(cls, raw_tx, sender_account):
     tx_hash = raw_tx.hash()
     signature = sender_account.sign(tx_hash)[:64]
     return SignedTransaction(raw_tx,
                              bytes_to_int_list(sender_account.public_key),
                              bytes_to_int_list(signature))
예제 #8
0
 def normalize_to_int_list(address):
     if isinstance(address, list):
         if len(address) != ADDRESS_LENGTH:
             raise ValueError(f"{address} is not a valid address.")
         return address
     return bytes_to_int_list(Address.normalize_to_bytes(address))