def _from_json_data_object(self, data): # decode sender info if 'sender' in data: bot_data = data['sender'] self._sender_botid = int(bot_data.get('id', 0) or 0) self._sender_signature = ED25519Signature.from_json(bot_data.get('signature', None) or None) else: self._sender_botid = None self._sender_signature = None # decode receiver info if 'receiver' in data: bot_data = data['receiver'] self._receiver_botid = int(bot_data.get('id', 0) or 0) self._receiver_signature = ED25519Signature.from_json(bot_data.get('signature', None) or None) else: self._receiver_botid = None self._receiver_signature = None # decode names self._names = [BotName.from_json(name) for name in data.get('names', []) or []] # decode transaction fee if 'txfee' in data: self._transaction_fee = Currency.from_json(data['txfee']) else: self._transaction_fee = None # decode coin inputs self._coin_inputs = [CoinInput.from_json(ci) for ci in data.get('coininputs', []) or []] # decode refund coin output if 'refundcoinoutput' in data: self._refund_coin_output = CoinOutput.from_json(data['refundcoinoutput']) else: self._refund_coin_output = None
def _from_json_data_object(self, data): self._addresses = [ NetworkAddress.from_json(address) for address in data.get('addresses', []) or [] ] self._names = [ BotName.from_json(name) for name in data.get('names', []) or [] ] self._number_of_months = int(data.get('nrofmonths', 0) or 0) if 'txfee' in data: self._transaction_fee = Currency.from_json(data['txfee']) else: self._transaction_fee = None self._coin_inputs = [ CoinInput.from_json(ci) for ci in data.get('coininputs', []) or [] ] if 'refundcoinoutput' in data: self._refund_coin_output = CoinOutput.from_json( data['refundcoinoutput']) else: self._refund_coin_output = None if 'identification' not in data or data['identification'] in (None, {}): self._public_key = None self._signature = None else: identification = data['identification'] self._public_key = PublicKey.from_json(identification['publickey']) self._signature = ED25519Signature.from_json( identification['signature'], as_array=True)
def _from_json_data_object(self, data): self._botid = int(data.get('id', 0) or 0) addresses = data.get('addresses', {}) or {} self._addresses_to_add = [ NetworkAddress.from_json(address) for address in addresses.get('add', []) or [] ] self._addresses_to_remove = [ NetworkAddress.from_json(address) for address in addresses.get('remove', []) or [] ] names = data.get('names', {}) or {} self._names_to_add = [ BotName.from_json(name) for name in names.get('add', []) or [] ] self._names_to_remove = [ BotName.from_json(name) for name in names.get('remove', []) or [] ] self._number_of_months = int(data.get('nrofmonths', 0) or 0) if 'txfee' in data: self._transaction_fee = Currency.from_json(data['txfee']) else: self._transaction_fee = None self._coin_inputs = [ CoinInput.from_json(ci) for ci in data.get('coininputs', []) or [] ] if 'refundcoinoutput' in data: self._refund_coin_output = CoinOutput.from_json( data['refundcoinoutput']) else: self._refund_coin_output = None self._signature = ED25519Signature.from_json( data.get('signature', None) or None)
def _from_json_data_object(self, data): # decode public key if 'pubkey' in data: self._public_key = PublicKey.from_json(data['pubkey']) else: self._public_key = None # decode signature if 'signature' in data: self._signature = ED25519Signature.from_json(data['signature']) else: self._signature = None # decode registration fee if 'regfee' in data: self.registration_fee = Currency.from_json(data['regfee']) else: self.registration_fee = None # decode transaction fee if 'txfee' in data: self._transaction_fee = Currency.from_json(data['txfee']) else: self._transaction_fee = None # decode coin inputs self._coin_inputs = [ CoinInput.from_json(ci) for ci in data.get('coininputs', []) or [] ] # decode refund coin output (if it exists) if 'refundcoinoutput' in data: self._refund_coin_output = CoinOutput.from_json( data['refundcoinoutput']) else: self._refund_coin_output = None
def _from_json_data_object(self, data): # decode address if 'address' in data: self._address = ERC20Address.from_json(data['address']) else: self._address = None # decode value if 'value' in data: self._value = Currency.from_json(data['value']) else: self._value = None # decode transaction fee if 'txfee' in data: self._transaction_fee = Currency.from_json(data['txfee']) else: self._transaction_fee = None # decode coin inputs self._coin_inputs = [ CoinInput.from_json(ci) for ci in data.get('coininputs', []) or [] ] # decode refund coin output (if it exists) if 'refundcoinoutput' in data: self._refund_coin_output = CoinOutput.from_json( data['refundcoinoutput']) else: self._refund_coin_output = None
def _transaction_from_explorer_transaction( self, etxn, endpoint="/?", resp=None): # keyword parameters for error handling purposes only if resp == None: resp = jsobj.new_dict() # parse the transactions transaction = transactions.from_json(obj=etxn['rawtransaction'], id=etxn['id']) # add the parent (coin) outputs coininputoutputs = etxn.get_or('coininputoutputs', None) or [] if len(transaction.coin_inputs) != len(coininputoutputs): raise tferrors.ExplorerInvalidResponse( "amount of coin inputs and parent outputs are not matching: {} != {}" .format(len(transaction.coin_inputs), len(coininputoutputs)), endpoint, resp) for (idx, co) in enumerate(coininputoutputs): co = CoinOutput.from_json(obj=co) co.id = transaction.coin_inputs[idx].parentid transaction.coin_inputs[idx].parent_output = co # add the coin output ids coinoutputids = etxn.get_or('coinoutputids', None) or [] if len(transaction.coin_outputs) != len(coinoutputids): raise tferrors.ExplorerInvalidResponse( "amount of coin outputs and output identifiers are not matching: {} != {}" .format(len(transaction.coin_outputs), len(coinoutputids)), endpoint, resp) for (idx, id) in enumerate(coinoutputids): transaction.coin_outputs[idx].id = Hash.from_json(obj=id) # add the parent (blockstake) outputs blockstakeinputoutputs = etxn.get_or('blockstakeinputoutputs', None) or [] if len(transaction.blockstake_inputs) != len(blockstakeinputoutputs): raise tferrors.ExplorerInvalidResponse( "amount of blockstake inputs and parent outputs are not matching: {} != {}" .format(len(transaction.blockstake_inputs), len(blockstakeinputoutputs)), endpoint, resp) for (idx, bso) in enumerate(blockstakeinputoutputs): bso = BlockstakeOutput.from_json(obj=bso) bso.id = transaction.blockstake_inputs[idx].parentid transaction.blockstake_inputs[idx].parent_output = bso # add the blockstake output ids blockstakeoutputids = etxn.get_or('blockstakeoutputids', None) or [] if len(transaction.blockstake_outputs) != len(blockstakeoutputids): raise tferrors.ExplorerInvalidResponse( "amount of blokstake outputs and output identifiers are not matching: {} != {}" .format(len(transaction.blockstake_inputs), len(blockstakeoutputids)), endpoint, resp) for (idx, id) in enumerate(blockstakeoutputids): transaction.blockstake_outputs[idx].id = Hash.from_json(obj=id) # set the unconfirmed state transaction.unconfirmed = etxn.get_or('unconfirmed', False) # set the blockid and height of the transaction only if confirmed if not transaction.unconfirmed: transaction.height = int(etxn.get_or('height', -1)) transaction.blockid = etxn.get_or('parent', None) # return the transaction return transaction
def _from_json_data_object(self, data): self._coin_inputs = [CoinInput.from_json( ci) for ci in data.get('coininputs', []) or []] self._coin_outputs = [CoinOutput.from_json( co) for co in data.get('coinoutputs', []) or []] self._blockstake_inputs = [BlockstakeInput.from_json( bsi) for bsi in data.get('blockstakeinputs', []) or []] self._blockstake_outputs = [BlockstakeOutput.from_json( bso) for bso in data.get('blockstakeoutputs', []) or []] self._miner_fees = [Currency.from_json( fee) for fee in data.get('minerfees', []) or []] self._data = BinaryData.from_json( data.get('arbitrarydata', None) or '', strencoding='base64')
def _from_json_data_object(self, data): self._nonce = BinaryData.from_json(data.get('nonce', ''), strencoding='base64') self._mint_fulfillment = fulfillments.from_json( data.get('mintfulfillment', {})) self._coin_outputs = [ CoinOutput.from_json(co) for co in data.get('coinoutputs', []) or [] ] self._miner_fees = [ Currency.from_json(fee) for fee in data.get('minerfees', []) or [] ] self._data = BinaryData.from_json(data.get('arbitrarydata', None) or '', strencoding='base64')
def legacy_from_json(cls, obj): """ Class method to decode v1 Tx from a legacy v0 Tx. """ tv = obj.get('version', -1) if TransactionVersion.LEGACY != tv: raise ValueError("legacy v0 transaction is expected to be of version {}, not version {}".format( TransactionVersion.LEGACY, tv)) txn = cls() if 'data' not in obj: raise ValueError("no data object found in Legacy Transaction (v{})".format( TransactionVersion.LEGACY)) txn_data = obj['data'] if 'coininputs' in txn_data: for legacy_ci_info in (txn_data['coininputs'] or []): unlocker = legacy_ci_info.get('unlocker', {}) ci_info = { 'parentid': legacy_ci_info.get('parentid', ''), 'fulfillment': { 'type': 1, 'data': { 'publickey': unlocker.get('condition', {}).get('publickey'), 'signature': unlocker.get('fulfillment', {}).get('signature'), } } } ci = CoinInput.from_json(ci_info) txn._coin_inputs.append(ci) if 'coinoutputs' in txn_data: for legacy_co_info in (txn_data['coinoutputs'] or []): co_info = { 'value': legacy_co_info.get('value', '0'), 'condition': { 'type': 1, 'data': { 'unlockhash': legacy_co_info.get('unlockhash', ''), } } } co = CoinOutput.from_json(co_info) txn._coin_outputs.append(co) if 'blockstakeinputs' in txn_data: for legacy_bsi_info in (txn_data['blockstakeinputs'] or []): unlocker = legacy_bsi_info.get('unlocker', {}) bsi_info = { 'parentid': legacy_bsi_info.get('parentid', ''), 'fulfillment': { 'type': 1, 'data': { 'publickey': unlocker.get('condition', {}).get('publickey'), 'signature': unlocker.get('fulfillment', {}).get('signature'), } } } bsi = BlockstakeInput.from_json(bsi_info) txn._blockstake_inputs.append(bsi) if 'blockstakeoutputs' in txn_data: for legacy_bso_info in (txn_data['blockstakeoutputs'] or []): bso_info = { 'value': legacy_bso_info.get('value', '0'), 'condition': { 'type': 1, 'data': { 'unlockhash': legacy_bso_info.get('unlockhash', ''), } } } bso = BlockstakeOutput.from_json(bso_info) txn._blockstake_outputs.append(bso) if 'minerfees' in txn_data: for miner_fee in (txn_data['minerfees'] or []): txn._miner_fees.append(Currency.from_json(miner_fee)) if 'arbitrarydata' in txn_data: txn._data = BinaryData.from_json(txn_data.get( 'arbitrarydata', None) or '', strencoding='base64') txn._legacy = True return txn