def compareConstructedTX(self):
        #    def test_online(self):
        #        self.maxDiff = None
        op = transactions.Override_transfer(
            **{
                "fee": {
                    "amount": 0,
                    "asset_id": "1.3.0"
                },
                "issuer": "1.2.29",
                "from": "1.2.104",
                "to": "1.2.29",
                "amount": {
                    "amount": 100000,
                    "asset_id": "1.3.105"
                },
                "extensions": []
            })

        ops = [transactions.Operation(op)]
        tx = transactions.Signed_Transaction(ref_block_num=ref_block_num,
                                             ref_block_prefix=ref_block_prefix,
                                             expiration=expiration,
                                             operations=ops)
        tx = tx.sign([wif], chain=prefix)
        txWire = hexlify(bytes(tx)).decode("ascii")

        from grapheneapi.grapheneapi import GrapheneAPI
        rpc = GrapheneAPI("localhost", 8092)
        compare = rpc.serialize_transaction(transactions.JsonObj(tx))
        print(compare[:-130])
        print(txWire[:-130])
        print(txWire[:-130] == compare[:-130])
        self.assertEqual(compare[:-130], txWire[:-130])
Exemplo n.º 2
0
def executeOps(ops, wifs=None):
    if any([not w for w in wifs]):
        print("Missing required key")
        return

    expiration = transactions.formatTimeFromNow(30)
    ops = transactions.addRequiredFees(rpc, ops, "1.3.0")
    ref_block_num, ref_block_prefix = transactions.getBlockParams(rpc)
    tx     = transactions.Signed_Transaction(
        ref_block_num=ref_block_num,
        ref_block_prefix=ref_block_prefix,
        expiration=expiration,
        operations=ops
    )
    tx = tx.sign(wifs, "BTS")

    pprint(transactions.JsonObj(tx))

    if not args.nobroadcast:
        reply = broadcastTx(tx)
        if reply:
            print(reply)
    else:
        print("Not broadcasting anything!")
        reply = None
Exemplo n.º 3
0
    def test_jsonLoading(self):
        data1 = {
            "expiration":
            expiration,
            "extensions": [],
            "operations": [[
                0, {
                    "amount": {
                        "amount": 1000000,
                        "asset_id": "1.3.4"
                    },
                    "extensions": [],
                    "fee": {
                        "amount": 0,
                        "asset_id": "1.3.0"
                    },
                    "from": "1.2.0",
                    "memo": {
                        "from":
                        "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
                        "message":
                        "fa5b6e83079a878e499e2e52a76a7739e9de40986a8e3bd8a68ce316cee50b21",
                        "nonce":
                        5862723643998573708,
                        "to":
                        "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
                    },
                    "to": "1.2.1"
                }
            ]],
            "ref_block_num":
            ref_block_num,
            "ref_block_prefix":
            ref_block_prefix,
            "signatures": [
                "1f6c1e8df5faf18c3b057ce713ec92f9b487c1ba58138daabc0038741b402c930d63d8d63861740215b4f65eb8ac9185a3987f8239b962181237f47189e21102af"
            ]
        }
        a = transactions.Signed_Transaction(data1.copy())
        data2 = transactions.JsonObj(a)

        check1 = data1
        check2 = data2
        for key in [
                "expiration", "extensions", "ref_block_num",
                "ref_block_prefix", "signatures"
        ]:
            self.assertEqual(check1[key], check2[key])

        check1 = data1["operations"][0][1]
        check2 = data2["operations"][0][1]
        for key in ["from", "to"]:
            self.assertEqual(check1[key], check2[key])

        check1 = data1["operations"][0][1]["memo"]
        check2 = data2["operations"][0][1]["memo"]
        for key in check1:
            self.assertEqual(check1[key], check2[key])
Exemplo n.º 4
0
def constructSignedTransaction(ops):
    ops        = transactions.addRequiredFees(client.ws, ops, "1.3.0")
    ref_block_num, ref_block_prefix = transactions.getBlockParams(client.ws)
    expiration = transactions.formatTimeFromNow(30)
    signed     = transactions.Signed_Transaction(ref_block_num, ref_block_prefix, expiration, ops)

    pprint(transactions.JsonObj(signed))
    w          = signed.sign(wifs, chain=client.getChainInfo())
    return w
Exemplo n.º 5
0
 async def build_transaction(self, _ops):
     if not _ops:
         return
     result = await self.ddp_client.rpc('getFee', [_ops])
     for idx, _op in enumerate(_ops):
         _op[1]['fee'] = result[idx]
     expiration = transactions.formatTimeFromNow(30)
     ref_block_num, ref_block_prefix = self.get_ref_block()
     transaction = transactions.Signed_Transaction(
         ref_block_num=ref_block_num,
         ref_block_prefix=ref_block_prefix,
         expiration=expiration,
         operations=_ops)
     transaction = transaction.sign([self.wif], 'BTS')
     transaction = transactions.JsonObj(transaction)
     await self.ddp_client.rpc('broadcast', [transaction])
Exemplo n.º 6
0
    def compareConstructedTX(self):
        #    def test_online(self):
        #        self.maxDiff = None
        op = transactions.Account_create(
            **{
                "fee": {
                    "amount": 1467634,
                    "asset_id": "1.3.0"
                },
                "registrar": "1.2.33",
                "referrer": "1.2.27",
                "referrer_percent": 3,
                "name": "foobar-f124",
                "owner": {
                    "weight_threshold":
                    1,
                    "account_auths": [],
                    "key_auths": [[
                        "BTS5TPTziKkLexhVKsQKtSpo4bAv5RnB8oXcG4sMHEwCcTf3r7dqE",
                        1
                    ]],
                    "address_auths": []
                },
                "active": {
                    "weight_threshold":
                    1,
                    "account_auths": [],
                    "key_auths": [[
                        "BTS5TPTziKkLexhVKsQKtSpo4bAv5RnB8oXcG4sMHEwCcTf3r7dqE",
                        1
                    ]],
                    "address_auths": []
                },
                "options": {
                    "memo_key":
                    "BTS5TPTziKkLexhVKsQKtSpo4bAv5RnB8oXcG4sMHEwCcTf3r7dqE",
                    "voting_account":
                    "1.2.5",
                    "num_witness":
                    26,
                    "num_committee":
                    8,
                    "votes": [
                        "1:22", "1:23", "1:24", "1:25", "1:26", "1:27", "1:28",
                        "1:30", "1:31", "1:32", "1:34", "1:35", "1:36", "1:37",
                        "1:38", "1:40", "1:41", "1:44", "1:45", "1:49", "1:51",
                        "1:56", "1:60", "0:76", "0:84", "0:87", "0:88", "0:91",
                        "0:141", "1:143", "0:147", "2:148", "2:150", "1:165",
                        "1:166", "2:171", "0:173", "2:179"
                    ],
                    "extensions": []
                },
                "extensions": {}
            })

        ops = [transactions.Operation(op)]
        tx = transactions.Signed_Transaction(ref_block_num=ref_block_num,
                                             ref_block_prefix=ref_block_prefix,
                                             expiration=expiration,
                                             operations=ops)
        tx = tx.sign([wif], chain=prefix)
        tx.verify([PrivateKey(wif).pubkey], "BTS")
        txWire = hexlify(bytes(tx)).decode("ascii")
        pprint(transactions.JsonObj(tx))

        from grapheneapi.grapheneapi import GrapheneAPI
        rpc = GrapheneAPI("localhost", 8092)
        compare = rpc.serialize_transaction(transactions.JsonObj(tx))
        print(compare[:-130])
        print(txWire[:-130])
        print(txWire[:-130] == compare[:-130])
        self.assertEqual(compare[:-130], txWire[:-130])
Exemplo n.º 7
0
class Config():
    witness_url           = witness_url


if __name__ == '__main__':
    config = Config
    client = GrapheneClient(config)

    issuer = client.ws.get_account(issuer)
    from_account = client.ws.get_account(from_account)
    to_account = client.ws.get_account(to_account)
    asset = client.ws.get_asset(asset)
    amount = int(amount * 10 ** asset["precision"])

    ops = []
    op = transactions.Override_transfer(**{
        "fee": {"amount": 0,
                "asset_id": "1.3.0"},
        "issuer": issuer["id"],
        "from": from_account["id"],
        "to": to_account["id"],
        "amount": {"amount": amount,
                   "asset_id": asset["id"]},
        "extensions": []
    })
    ops.append(transactions.Operation(op))

    tx = constructSignedTransaction(ops)
    pprint(transactions.JsonObj(tx))
    print(client.ws.broadcast_transaction(transactions.JsonObj(tx), api="network_broadcast"))
Exemplo n.º 8
0
def broadcastTx(tx):
    if isinstance(tx, transactions.Signed_Transaction):
        tx     = transactions.JsonObj(tx)
    return rpc.broadcast_transaction(tx, api="network_broadcast")