def deposit(self, payer_wif, payee_pubkey, spend_secret_hash, expire_time, quantity): """Create deposit for given quantity. Args: payer_wif: TODO doc string payee_pubkey: TODO doc string spend_secret_hash: TODO doc string expire_time: TODO doc string quantity: In satoshis Returns: Transaction ID for the created deposit. Raises: ValueError if invalid quantity InsufficientFunds if not enough funds to cover requested quantity. """ # TODO validate input # TODO validate pubkeys on blockchain (required by counterparty) with self.mutex: self.clear() self.payer_wif = payer_wif rawtx, script = self.control.deposit(self.payer_wif, payee_pubkey, spend_secret_hash, expire_time, quantity) self.deposit_rawtx = rawtx self.deposit_script_hex = util.b2h(script) return {"rawtx": rawtx, "script": util.b2h(script)}
def deposit(self, payer_wif, payee_pubkey, spend_secret_hash, expire_time, quantity): """Create deposit for given quantity. Args: payer_wif: TODO doc string payee_pubkey: TODO doc string spend_secret_hash: TODO doc string expire_time: TODO doc string quantity: In satoshis Returns: Transaction ID for the created deposit. Raises: ValueError if invalid quantity InsufficientFunds if not enough funds to cover requested quantity. """ # TODO validate input # TODO validate pubkeys on blockchain (required by counterparty) with self.mutex: self.clear() self.payer_wif = payer_wif rawtx, script = self.control.deposit( self.payer_wif, payee_pubkey, spend_secret_hash, expire_time, quantity ) self.deposit_rawtx = rawtx self.deposit_script_hex = util.b2h(script) return {"rawtx": rawtx, "script": util.b2h(script)}
def setup(self, payee_wif): with self.mutex: self.clear() self.payee_wif = payee_wif payee_pubkey = util.wif2pubkey(self.payee_wif) secret = os.urandom(32) # secure random number self.spend_secret = util.b2h(secret) spend_secret_hash = util.b2h(util.hash160(secret)) return payee_pubkey, spend_secret_hash
def request_commit(self, quantity): with self.mutex: self._validate_transfer_quantity(quantity) secret = util.b2h(os.urandom(32)) # secure random number secret_hash = util.hash160hex(secret) self.commits_requested.append(secret) return quantity, secret_hash
def get_spend_secret_hash(self): with self.mutex: if self.spend_secret is not None: # payee return util.b2h(util.hash160(util.h2b(self.spend_secret))) elif self.deposit_script_hex is not None: # payer script = util.h2b(self.deposit_script_hex) return get_deposit_spend_secret_hash(script) else: # undefined raise Exception("Undefined state, not payee or payer.")
def create_commit(self, quantity, revoke_secret_hash, delay_time): with self.mutex: self._validate_transfer_quantity(quantity) rawtx, script = self.control.create_commit( self.payer_wif, util.h2b(self.deposit_script_hex), quantity, revoke_secret_hash, delay_time ) script_hex = util.b2h(script) self._order_active() self.commits_active.append({ "rawtx": rawtx, "script": script_hex, "revoke_secret": None }) return {"rawtx": rawtx, "script": script_hex}
def create_commit(self, quantity, revoke_secret_hash, delay_time): with self.mutex: self._validate_transfer_quantity(quantity) rawtx, script = self.control.create_commit( self.payer_wif, util.h2b(self.deposit_script_hex), quantity, revoke_secret_hash, delay_time) script_hex = util.b2h(script) self._order_active() self.commits_active.append({ "rawtx": rawtx, "script": script_hex, "revoke_secret": None }) return {"rawtx": rawtx, "script": script_hex}