Given ledger transaction, return its data json.

        :param txn: transaction as dict
        :return: transaction data json
175592
def txn2data(self, txn: dict) -> str:
        

        rv_json = json.dumps({})
        if self == Protocol.V_13:
            rv_json = json.dumps(txn['result'].get('data', {}))
        else:
            rv_json = json.dumps((txn['result'].get('data', {}) or {}).get('txn', {}))  # "data": null for no such txn

        return rv_json
127638
def ToJson(self):
        
        obj = {
            'usage': self.Usage,
            'data': '' if not self.Data else self.Data.hex()
        }
        return obj
1100928
def reqToTxn(req):
    
    if isinstance(req, str):
        req = json.loads(req)
    if isinstance(req, dict):
        kwargs = dict(
            identifier=req.get(f.IDENTIFIER.nm, None),
            reqId=req.get(f.REQ_ID.nm, None),
            operation=req.get(OPERATION, None),
            signature=req.get(f.SIG.nm, None),
            signatures=req.get(f.SIGS.nm, None),
            protocolVersion=req.get(f.PROTOCOL_VERSION.nm, None)
        )
        req = TxnUtilConfig.client_request_class(**kwargs)
    if isinstance(req, Request):
        req_data = req.as_dict
        req_data[f.DIGEST.nm] = req.digest
        req_data[f.PAYLOAD_DIGEST.nm] = req.payload_digest
    else:
        raise TypeError(
            "Expected dict or str as input, but got: {}".format(type(req)))

    req_data = deepcopy(req_data)
    return do_req_to_txn(req_data=req_data,
                         req_op=req_data[OPERATION])
777334
def transactions(self, time=TransRange.HOUR, base="btc", quote="usd"):
        
        params = {'time': time}
        url = self._construct_url("transactions/", base, quote)
        return self._get(url, params=params, return_json=True, version=2)
339458
def get_data(self, contract=None):
        """"""
        if contract is None:
            return self._data
        if contract in self._data.keys():
            return {contract: self._data[contract]}
        raise PyHydroQuebecError("Contract {} not found".format(contract))
1002520
def get_contract_data(self, contract_name):
        

        contract_data_path = self.output_dir + '/{0}.json'.format(contract_name)
        with open(contract_data_path, 'r') as contract_data_file:
            contract_data = json.load(contract_data_file)

        abi = contract_data['abi']
        bytecode = contract_data['evm']['bytecode']['object']

        return abi, bytecode
767746
def json(self):
        
        try:
            return self._json
        except AttributeError:
            try:
                self._json = json.loads(self.text)
                return self._json
            except:  # noqa e722
                raise RequestInvalidJSON("Invalid JSON received")
135392
def tx_for_tx_hash(self, tx_hash):
        
        try:
            url_append = "?token=%s&includeHex=true" % self.api_key
            url = self.base_url("txs/%s%s" % (b2h_rev(tx_hash), url_append))
            result = json.loads(urlopen(url).read().decode("utf8"))
            tx = Tx.parse(io.BytesIO(h2b(result.get("hex"))))
            return tx
        except Exception:
            raise Exception
132692
def to_json(self):
        
        data = dict(self.__dict__)
        data.pop('context',None)
        data['oauth'] = self.oauth.to_dict()
        data['cache'] = self.cache.to_dict()
        return json.dumps(data)
675042
def get_transaction_document(current_block: dict, source: dict, from_pubkey: str, to_pubkey: str) -> Transaction:
    
    # list of inputs (sources)
    inputs = [
        InputSource(
            amount=source['amount'],
            base=source['base'],
            source=source['type'],
            origin_id=source['identifier'],
            index=source['noffset']
        )
    ]

    # list of issuers of the inputs
    issuers = [
        from_pubkey
    ]

    # list of unlocks of the inputs
    unlocks = [
        Unlock(
            # inputs[index]
            index=0,
            # unlock inputs[index] if signatures[0] is from public key of issuers[0]
            parameters=[SIGParameter(0)]
        )
    ]

    # lists of outputs
    outputs = [
        OutputSource(amount=source['amount'], base=source['base'], condition="SIG({0})".format(to_pubkey))
    ]

    transaction = Transaction(
        version=TRANSACTION_VERSION,
        currency=current_block['currency'],
        blockstamp=BlockUID(current_block['number'], current_block['hash']),
        locktime=0,
        issuers=issuers,
        inputs=inputs,
        unlocks=unlocks,
        outputs=outputs,
        comment='',
        signatures=[]
    )

    return transaction
443027
def to_json(self):
        
        return {
            "xblock_id": six.text_type(self.xblock_id),
            "messages": [message.to_json() for message in self.messages],
            "empty": self.empty
        }
746620
def txinfo(self, txid: str) -> dict:
        ''''''

        return cast(dict, self.ext_fetch('txinfo/' + txid))
112902
def send_raw_transaction(self, tx: Transaction, is_full: bool = False) -> str:
        
        tx_data = tx.serialize(is_hex=True)
        payload = self.generate_json_rpc_payload(RpcMethod.SEND_TRANSACTION, [tx_data])
        response = self.__post(self.__url, payload)
        if is_full:
            return response
        return response['result']
338363
def ToJson(self):
        
        parameters = self.ParameterList.hex()
        paramlist = [ToName(ContractParameterType.FromString(parameters[i:i + 2]).value) for i in range(0, len(parameters), 2)]
        return {
            'hash': self.ScriptHash().To0xString(),
            'script': self.Script.hex(),
            'parameters': paramlist,
            'returntype': ToName(self.ReturnType) if type(self.ReturnType) is int else ToName(int(self.ReturnType))
        }
515710
def ToJson(self):
        
        json = super(Block, self).ToJson()
        if self.Transactions[0] and isinstance(self.Transactions[0], str):
            json['tx'] = ['0x%s' % tx for tx in self.Transactions]
        else:
            json['tx'] = [tx.ToJson() for tx in self.Transactions]

        # json['sys_fee'] = GetBlockchain().GetSysFeeAmount(self.Hash)
        return json
401199
def ledger(self):
        """"""
        self.balance()  # make sure the transaction balances

        s = "{0}/{1:02}/{2:02}  {3}\n".format(
            self.date.year,
            self.date.month,
            self.date.day,
            self.desc.replace('\n', ' ')
        )
        for src in self.src:
            s += "  {0.account}  ${0.amount}\n".format(src)
        for dst in self.dst:
            s += "  {0.account}  ${0.amount}\n".format(dst)
        return s
849769
def get_transaction(cls, txid):
        

        for api_call in cls.GET_TX_MAIN:
            try:
                return api_call(txid)
            except cls.IGNORED_ERRORS:
                pass

        raise ConnectionError('All APIs are unreachable.')