Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
 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')
Exemplo n.º 7
0
    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