def new(cls, contract, type_expr): assert is_pkh(contract[:36]) or is_kt( contract[:36]), f'expected contract, got {contract}' if len(contract) > 36: assert contract[36] == '%', f'expected contract, got {contract}' return cls(val=contract, val_expr={'string': contract}, type_expr={ 'prim': cls.prim, 'args': [type_expr] })
def __init__(self, key, interval=5, shell=mainnet): """ :param key: secret key (encrypted/unencrypted), public key or public key hash, all base58 encoded :param interval: number of blocks to check (tolerance) :param shell: ShellQuery instance """ if not isinstance(key, Key): if is_pkh(key): key = shell.public_key(key) key = Key.from_encoded_key(key) self._key = key self._interval = interval self._shell = shell
def __init__(self, shell=None, key=None): if shell is None: shell = default_shell if isinstance(shell, str): networks = { 'mainnet': mainnet, 'babylonnet': babylonnet, 'carthagenet': carthagenet, 'zeronet': zeronet, 'sandboxnet': localhost.sandboxnet, 'bbbox': localhost.bbbox, 'labnet': labnet, 'mainnet-pool': pool.mainnet } if shell in networks: self.shell = networks[shell] else: self.shell = ShellQuery(node=RpcNode(uri=shell)) elif isinstance(shell, ShellQuery): self.shell = shell else: raise NotImplementedError(shell) if key is None: key = default_key if is_installed() else default_key_hash if isinstance(key, str): keys = { 'alice': alice_key } if key in keys: self.key = keys[key] elif is_key(key): self.key = Key.from_encoded_key(key) elif is_pkh(key): self.key = KeyHash(key) elif exists(expanduser(key)): self.key = Key.from_faucet(key) else: self.key = Key.from_alias(key) elif isinstance(key, Key): self.key = key else: raise NotImplementedError(key)
def test_is_pkh(self, value, expected): self.assertEqual(expected, is_pkh(value))
def new(cls, key_hash): assert is_pkh(key_hash), f'expected key hash, got {key_hash}' return cls(val=key_hash, val_expr={'string': key_hash}, type_expr={'prim': cls.prim})
def new(cls, address): assert is_pkh(address) or is_kt( address), f'expected address, got {address}' return cls(val=address, val_expr={'string': address}, type_expr={'prim': cls.prim})