def from_bytes(cls, serialized: bytes) -> "Lock": return cls( expiration=BlockExpiration( int.from_bytes(serialized[:32], byteorder="big")), amount=PaymentWithFeeAmount( int.from_bytes(serialized[32:64], byteorder="big")), secrethash=SecretHash(serialized[64:]), )
def __init__(self, chain_state: ChainState, channel_state: NettingChannelState): self.secret = random_secret() self.secrethash = SecretHash(sha3(self.secret)) self.lock_expiration = get_initial_lock_expiration( chain_state.block_number, channel_state.reveal_timeout) self.payment_identifier = PaymentID(create_default_identifier()) self.message_identifier = MessageID( message_identifier_from_prng(chain_state.pseudo_random_generator))
def from_dict(cls, data: Dict[str, Any]) -> "ReceiveSecretRequest": instance = cls( payment_identifier=PaymentID(int(data["payment_identifier"])), amount=PaymentAmount(int(data["amount"])), expiration=BlockExpiration(int(data["expiration"])), secrethash=SecretHash(deserialize_bytes(data["secrethash"])), sender=to_canonical_address(data["sender"]), ) instance.revealsecret = data["revealsecret"] return instance
def from_dict(cls, data: Dict[str, Any]) -> 'ReceiveSecretRequest': instance = cls( payment_identifier=PaymentID(int(data['payment_identifier'])), amount=PaymentAmount(int(data['amount'])), expiration=BlockExpiration(int(data['expiration'])), secrethash=SecretHash(deserialize_bytes(data['secrethash'])), sender=to_canonical_address(data['sender']), ) instance.revealsecret = data['revealsecret'] return instance
def from_dict(cls, data: Dict[str, Any]) -> 'SendSecretRequest': restored = cls( recipient=to_canonical_address(data['recipient']), channel_identifier=ChannelID(int(data['channel_identifier'])), message_identifier=MessageID(int(data['message_identifier'])), payment_identifier=PaymentID(int(data['payment_identifier'])), amount=TokenAmount(int(data['amount'])), expiration=BlockExpiration(int(data['expiration'])), secrethash=SecretHash(serialization.deserialize_bytes(data['secrethash'])), ) return restored
def __init__(self, message_identifier: MessageID, secret: Secret, balance_proof: BalanceProofSignedState) -> None: if not isinstance(balance_proof, BalanceProofSignedState): raise ValueError( "balance_proof must be an instance of BalanceProofSignedState") super().__init__(balance_proof) secrethash: SecretHash = SecretHash(sha3(secret)) self.message_identifier = message_identifier self.secret = secret self.secrethash = secrethash
def deserialize_secret_hash(data: str) -> SecretHash: return SecretHash(deserialize_bytes(data))
# Set at 64 since parity's default is 64 and Geth's default is 128 # TODO: Make this configurable. Since in parity this is also a configurable value STATE_PRUNING_AFTER_BLOCKS = 64 STATE_PRUNING_SAFETY_MARGIN = 8 NO_STATE_QUERY_AFTER_BLOCKS = STATE_PRUNING_AFTER_BLOCKS - STATE_PRUNING_SAFETY_MARGIN NULL_ADDRESS_BYTES = bytes(20) NULL_ADDRESS_HEX = to_hex_address(Address(NULL_ADDRESS_BYTES)) NULL_ADDRESS_CHECKSUM = to_checksum_address(Address(NULL_ADDRESS_BYTES)) EMPTY_HASH = BlockHash(bytes(32)) EMPTY_BALANCE_HASH = BalanceHash(bytes(32)) EMPTY_MESSAGE_HASH = AdditionalHash(bytes(32)) EMPTY_SIGNATURE = Signature(bytes(65)) EMPTY_SECRET = Secret(bytes(32)) EMPTY_SECRETHASH = SecretHash(bytes(32)) EMPTY_SECRET_SHA256 = sha256_secrethash(EMPTY_SECRET) LOCKSROOT_OF_NO_LOCKS = Locksroot(keccak(b"")) EMPTY_LOCKSROOT = Locksroot(bytes(32)) ZERO_TOKENS = TokenAmount(0) ABSENT_SECRET = Secret(b"") SECRET_LENGTH = 32 SECRETHASH_LENGTH = 32 RECEIPT_FAILURE_CODE = 0 class EthClient(Enum): GETH = "geth"
def from_dict(cls, data: Dict[str, Any]) -> "ReceiveLockExpired": return cls( balance_proof=data["balance_proof"], secrethash=SecretHash(deserialize_bytes(data["secrethash"])), message_identifier=MessageID(int(data["message_identifier"])), )
def __repr__(self): secrethash: SecretHash = SecretHash(sha3(self.secret)) return ( '<ContractSendSecretReveal secrethash:{} triggered_by_block_hash:{}>' ).format(secrethash, pex(self.triggered_by_block_hash))
def __repr__(self): secrethash: SecretHash = SecretHash(sha3(self.secret)) return '<ContractSendSecretReveal secrethash:{}>'.format(secrethash)
def from_dict(cls, data: Dict[str, Any]) -> 'ReceiveLockExpired': return cls( balance_proof=data['balance_proof'], secrethash=SecretHash(deserialize_bytes(data['secrethash'])), message_identifier=MessageID(int(data['message_identifier'])), )
def sha256_secrethash(secret: Secret) -> SecretHash: """Compute the secret hash using sha256.""" return SecretHash(sha256(secret).digest())