예제 #1
0
    def test_sign_transaction_trust_wallet_scenario(self):
        # With data
        transaction = Transaction()
        transaction.nonce = 0
        transaction.value = "0"
        transaction.sender = "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"
        transaction.receiver = "erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r"
        transaction.gasPrice = 1000000000
        transaction.gasLimit = 50000
        transaction.data = "foo"
        transaction.chainID = "1"
        transaction.version = 1
        transaction.sign(self.alice)
        serialized = transaction.serialize().decode()

        self.assertEqual("""{"nonce":0,"value":"0","receiver":"erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r","sender":"erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz","gasPrice":1000000000,"gasLimit":50000,"data":"Zm9v","chainID":"1","version":1,"signature":"b5fddb8c16fa7f6123cb32edc854f1e760a3eb62c6dc420b5a4c0473c58befd45b621b31a448c5b59e21428f2bc128c80d0ee1caa4f2bf05a12be857ad451b00"}""", serialized)
        self.assertEqual("b5fddb8c16fa7f6123cb32edc854f1e760a3eb62c6dc420b5a4c0473c58befd45b621b31a448c5b59e21428f2bc128c80d0ee1caa4f2bf05a12be857ad451b00", transaction.signature)

        # Without data
        transaction = Transaction()
        transaction.nonce = 0
        transaction.value = "0"
        transaction.sender = "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"
        transaction.receiver = "erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r"
        transaction.gasPrice = 1000000000
        transaction.gasLimit = 50000
        transaction.data = ""
        transaction.chainID = "1"
        transaction.version = 1
        transaction.sign(self.alice)
        serialized = transaction.serialize().decode()

        self.assertEqual("""{"nonce":0,"value":"0","receiver":"erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r","sender":"erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz","gasPrice":1000000000,"gasLimit":50000,"chainID":"1","version":1,"signature":"3079d37bfbdbe66fbb4c4b186144f9d9ad5b4b08fbcd6083be0688cf1171123109dfdefdbabf91425c757ca109b6db6d674cb9aeebb19a1a51333565abb53109"}""", serialized)
        self.assertEqual("3079d37bfbdbe66fbb4c4b186144f9d9ad5b4b08fbcd6083be0688cf1171123109dfdefdbabf91425c757ca109b6db6d674cb9aeebb19a1a51333565abb53109", transaction.signature)
예제 #2
0
    def test_sign_transaction(self):
        # With data
        transaction = Transaction()
        transaction.nonce = 0
        transaction.value = "0"
        transaction.sender = "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"
        transaction.receiver = "erd188nydpkagtpwvfklkl2tn0w6g40zdxkwfgwpjqc2a2m2n7ne9g8q2t22sr"
        transaction.gasPrice = 200000000000000
        transaction.gasLimit = 500000000
        transaction.data = "foo"
        transaction.chainID = "chainID"
        transaction.version = 1
        transaction.sign(self.alice)

        self.assertEqual(
            "0e69f27e24aba2f3b7a8842dc7e7c085a0bfb5b29112b258318eed73de9c8809889756f8afaa74c7b3c7ce20a028b68ba90466a249aaf999a1a78dcf7f4eb40c",
            transaction.signature)

        # Without data
        transaction = Transaction()
        transaction.nonce = 0
        transaction.value = "0"
        transaction.sender = "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"
        transaction.receiver = "erd188nydpkagtpwvfklkl2tn0w6g40zdxkwfgwpjqc2a2m2n7ne9g8q2t22sr"
        transaction.gasPrice = 200000000000000
        transaction.gasLimit = 500000000
        transaction.data = ""
        transaction.chainID = "chainID"
        transaction.version = 1
        transaction.sign(self.alice)

        self.assertEqual(
            "83efd1bc35790ecc220b0ed6ddd1fcb44af6653dd74e37b3a49dcc1f002a1b98b6f79779192cca68bdfefd037bc81f4fa606628b751023122191f8c062362805",
            transaction.signature)
예제 #3
0
    def test_sign_transaction(self):
        # With data
        transaction = Transaction()
        transaction.nonce = 0
        transaction.value = "0"
        transaction.sender = "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"
        transaction.receiver = "erd188nydpkagtpwvfklkl2tn0w6g40zdxkwfgwpjqc2a2m2n7ne9g8q2t22sr"
        transaction.gasPrice = 200000000000000
        transaction.gasLimit = 500000000
        transaction.data = "foo"
        transaction.chainID = "chainID"
        transaction.version = 1
        transaction.sign(self.alice)

        self.assertEqual("f9878caeba4285a9fe66fa8127eb9f7e3f178de40f96727f639e31f0a503efd154d73752781ad06c788876342df39cec27863f5dd88e23c33a4f5a0c57015905", transaction.signature)

        # Without data
        transaction = Transaction()
        transaction.nonce = 0
        transaction.value = "0"
        transaction.sender = "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"
        transaction.receiver = "erd188nydpkagtpwvfklkl2tn0w6g40zdxkwfgwpjqc2a2m2n7ne9g8q2t22sr"
        transaction.gasPrice = 200000000000000
        transaction.gasLimit = 500000000
        transaction.data = ""
        transaction.chainID = "chainID"
        transaction.version = 1
        transaction.sign(self.alice)

        self.assertEqual("1ad14993a3cf6a5e0898a29271a2924fc34f80ba2a391dd2ff5c2fcc554e5a71eda0e34044f99888ec1a1da6d4cf82345e848cec69ccd27e192f8b66c4beaa0c", transaction.signature)    
예제 #4
0
    def test_sign_transaction_docs_scenario(self):
        # With data
        transaction = Transaction()
        transaction.nonce = 7
        transaction.value = "10000000000000000000"  # 10 ERD
        transaction.sender = "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"
        transaction.receiver = "erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r"
        transaction.gasPrice = 1000000000
        transaction.gasLimit = 70000
        transaction.data = "for the book"
        transaction.chainID = "1"
        transaction.version = 1
        serialized = transaction.serialize().decode()
        transaction.sign(self.alice)

        self.assertEqual("""{"nonce":7,"value":"10000000000000000000","receiver":"erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r","sender":"erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz","gasPrice":1000000000,"gasLimit":70000,"data":"Zm9yIHRoZSBib29r","chainID":"1","version":1}""", serialized)
        self.assertEqual("1702bb7696f992525fb77597956dd74059b5b01e88c813066ad1f6053c6afca97d6eaf7039b2a21cccc7d73b3e5959be4f4c16f862438c7d61a30c91e3d16c01", transaction.signature)

        # Without data
        transaction = Transaction()
        transaction.nonce = 8
        transaction.value = "10000000000000000000"
        transaction.sender = "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"
        transaction.receiver = "erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r"
        transaction.gasPrice = 1000000000
        transaction.gasLimit = 50000
        transaction.data = ""
        transaction.chainID = "1"
        transaction.version = 1
        serialized = transaction.serialize().decode()
        transaction.sign(self.alice)

        self.assertEqual("""{"nonce":8,"value":"10000000000000000000","receiver":"erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r","sender":"erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz","gasPrice":1000000000,"gasLimit":50000,"chainID":"1","version":1}""", serialized)
        self.assertEqual("4a6d8186eae110894e7417af82c9bf9592696c0600faf110972e0e5310d8485efc656b867a2336acec2b4c1e5f76c9cc70ba1803c6a46455ed7f1e2989a90105", transaction.signature)
예제 #5
0
def main():
    pem_file_name = "walletKey.pem"
    pem_path = "~/Elrond/testnet/filegen/output"

    pem_file = path.join(pem_path, pem_file_name)

    parser = ArgumentParser()
    parser.add_argument("--proxy", default="http://localhost:7950")
    args = parser.parse_args()

    shard0_index = get_index_by_shard_id(pem_file, 0)
    shard1_index = get_index_by_shard_id(pem_file, 1)

    logging.basicConfig(level=logging.DEBUG)

    proxy = ElrondProxy(args.proxy)
    network = proxy.get_network_config()

    alice = Account(pem_file=pem_file, pem_index=shard0_index)
    bob = Account(pem_file=pem_file, pem_index=shard1_index)

    bob.sync_nonce(proxy)

    innerTx = Transaction()
    innerTx.nonce = bob.nonce
    innerTx.value = "0"
    innerTx.sender = bob.address.bech32()
    innerTx.receiver = "erd1qqqqqqqqqqqqqpgqrchxzx5uu8sv3ceg8nx8cxc0gesezure5awqn46gtd"  # shard 2 address
    innerTx.gasPrice = 1000000000
    innerTx.gasLimit = 500000000
    innerTx.chainID = network.chain_id
    innerTx.version = network.min_tx_version
    innerTx.data = "version"
    innerTx.sign(bob)

    alice.sync_nonce(proxy)

    wrapperTx = Transaction()
    wrapperTx.nonce = alice.nonce
    wrapperTx.value = "0"
    wrapperTx.sender = alice.address.bech32()
    wrapperTx.receiver = bob.address.bech32()
    wrapperTx.gasPrice = 1000000000
    wrapperTx.gasLimit = 501109000
    wrapperTx.chainID = network.chain_id
    wrapperTx.version = network.min_tx_version
    wrapperTx.wrap_inner(innerTx)
    wrapperTx.sign(alice)

    wrapperTx.send(proxy)
예제 #6
0
    def execute(self,
                data,
                _sender=None,
                value="0",
                receiver=NFT_CONTRACT,
                gasLimit=60000000):
        if _sender is None: _sender = self._sender
        _sender.sync_nonce(self._proxy)

        t = Transaction()
        t.nonce = _sender.nonce
        t.version = get_tx_version()
        t.data = data
        t.receiver = receiver
        t.chainID = self._proxy.get_chain_id()
        t.gasLimit = gasLimit
        t.value = value
        t.sender = self._sender.address.bech32()
        t.gasPrice = DEFAULT_GAS_PRICE
        t.sign(self._sender)

        log("Execution d'une transaction sur " + BC_EXPLORER + "/address/" +
            t.sender)
        rc = t.send_wait_result(self._proxy, 60000)

        for r in rc["smartContractResults"]:
            if "data" in r:
                r["result"] = list()
                for p in r["data"].split("@"):
                    if len(p) > 0:
                        r["result"].append(hex_to_str(int(p, 16)))

        return rc["smartContractResults"]
예제 #7
0
    def test_serialize_transaction_payload(self):
        # With data field
        transaction = Transaction()
        transaction.nonce = 0
        transaction.value = "42"
        transaction.sender = "alice"
        transaction.receiver = "bob"
        transaction.gasPrice = 43
        transaction.gasLimit = 44
        transaction.data = "foobar"
        transaction.chainID = "BoN"
        transaction.version = 1
        serialized = transaction.serialize().decode()
        self.assertEqual(
            """{"nonce":0,"value":"42","receiver":"bob","sender":"alice","gasPrice":43,"gasLimit":44,"data":"Zm9vYmFy","chainID":"BoN","version":1}""",
            serialized)

        # Without data field
        transaction.data = ""
        serialized = transaction.serialize().decode()
        self.assertEqual(
            """{"nonce":0,"value":"42","receiver":"bob","sender":"alice","gasPrice":43,"gasLimit":44,"chainID":"BoN","version":1}""",
            serialized)

        # With actual addresses
        transaction = Transaction()
        transaction.nonce = 0
        transaction.value = "0"
        transaction.sender = "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"
        transaction.receiver = "erd188nydpkagtpwvfklkl2tn0w6g40zdxkwfgwpjqc2a2m2n7ne9g8q2t22sr"
        transaction.gasPrice = 200000000000000
        transaction.gasLimit = 500000000
        transaction.data = "foo"
        transaction.chainID = "BoN"
        transaction.version = 1
        serialized = transaction.serialize().decode()
        self.assertEqual(
            """{"nonce":0,"value":"0","receiver":"erd188nydpkagtpwvfklkl2tn0w6g40zdxkwfgwpjqc2a2m2n7ne9g8q2t22sr","sender":"erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz","gasPrice":200000000000000,"gasLimit":500000000,"data":"Zm9v","chainID":"BoN","version":1}""",
            serialized)
예제 #8
0
def tx1():
    tx1 = Transaction()
    tx1.nonce = getNonce()
    tx1.value = sendAmount1
    tx1.sender = sender
    tx1.receiver = wallet1
    tx1.gasPrice = 1000000000
    tx1.gasLimit = 50000
    tx1.data = ""
    tx1.chainID = "D"  # Currently set to the Devnet Chain
    tx1.version = 1
    tx1.sign(account)
    proxy1 = ElrondProxy("https://devnet-api.elrond.com")
    tx1.send(proxy1)
    print("Sent " + sendAmount1 + " to " + wallet1)
예제 #9
0
    def test_serialize_transaction_as_inner(self):
        transaction = Transaction()
        transaction.nonce = 0
        transaction.value = "0"
        transaction.sender = "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"
        transaction.receiver = "erd188nydpkagtpwvfklkl2tn0w6g40zdxkwfgwpjqc2a2m2n7ne9g8q2t22sr"
        transaction.gasPrice = 200000000000000
        transaction.gasLimit = 500000000
        transaction.data = "foo"
        transaction.chainID = "BoN"
        transaction.version = 1
        transaction.sign(self.alice)
        serialized = transaction.serialize_as_inner()

        self.assertEqual(
            "relayedTx@7b226e6f6e6365223a302c2276616c7565223a302c227265636569766572223a224f655a47687431437775596d33376655756233615256346d6d73354b48426b4443757132716670354b67343d222c2273656e646572223a222f576b62746568644543614832424235332f7a6f517454634d6f4a323074544744592f5277304d384d704d3d222c226761735072696365223a3230303030303030303030303030302c226761734c696d6974223a3530303030303030302c2264617461223a225a6d3976222c22636861696e4944223a22516d394f222c2276657273696f6e223a312c227369676e6174757265223a224a38433741664278376f594e79746b713542564845367a4f6f7563596a796a4e79375a47484961485139674f3354384a75442f325147507650724f694f58444b5031744274643338596a667a37384f736a624a7743673d3d227d",
            serialized)
예제 #10
0
    def test_serialize_transaction_as_inner(self):
        transaction = Transaction()
        transaction.nonce = 0
        transaction.value = "0"
        transaction.sender = "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"
        transaction.receiver = "erd188nydpkagtpwvfklkl2tn0w6g40zdxkwfgwpjqc2a2m2n7ne9g8q2t22sr"
        transaction.gasPrice = 200000000000000
        transaction.gasLimit = 500000000
        transaction.data = "foo"
        transaction.chainID = "BoN"
        transaction.version = 1
        transaction.sign(self.alice)
        serialized = transaction.serialize_as_inner()

        self.assertEqual(
            "relayedTx@7b226e6f6e6365223a302c2276616c7565223a302c227265636569766572223a224f655a47687431437775596d33376655756233615256346d6d73354b48426b4443757132716670354b67343d222c2273656e646572223a222f576b62746568644543614832424235332f7a6f517454634d6f4a323074544744592f5277304d384d704d3d222c226761735072696365223a3230303030303030303030303030302c226761734c696d6974223a3530303030303030302c2264617461223a225a6d3976222c22636861696e4944223a22516d394f222c2276657273696f6e223a312c227369676e6174757265223a2262516b49673975745968334a4f7a413036314e65785343515054397a6e57336d2f51732f746f544d43454741745a48752b56473670667a426571757a714e776d785476504d304b49652f6f5164534b345354514e43413d3d227d",
            serialized)
예제 #11
0
def send_one_tx(proxy: ElrondProxy, sender: Account, receiver_address: str):
    tx = Transaction()
    tx.nonce = sender.nonce
    tx.value = "20000000000000000"  # 0.02 ERD
    tx.sender = sender.address.bech32()
    tx.receiver = receiver_address
    tx.gasPrice = 1000000000
    tx.gasLimit = 50000
    tx.data = ""
    tx.chainID = config.get_chain_id()
    tx.version = config.get_tx_version()

    tx.signature = signing.sign_transaction(tx, sender)
    tx.send(proxy)

    global counter
    counter += 1
    print(f"Sent transaction #{counter}, with nonce = {tx.nonce}.")
예제 #12
0
    def upgrade(self, owner, arguments, gas_price, gas_limit, value, chain,
                version) -> Transaction:
        self.owner = owner

        arguments = arguments or []
        gas_price = int(gas_price or config.DEFAULT_GAS_PRICE)
        gas_limit = int(gas_limit)
        value = str(value or "0")

        tx = Transaction()
        tx.nonce = owner.nonce
        tx.value = value
        tx.sender = owner.address.bech32()
        tx.receiver = self.address.bech32()
        tx.gasPrice = gas_price
        tx.gasLimit = gas_limit
        tx.data = self.prepare_upgrade_transaction_data(arguments)
        tx.chainID = chain
        tx.version = version

        tx.sign(owner)
        return tx
예제 #13
0
    def execute(self, caller, function, arguments, gas_price, gas_limit, value,
                chain, version) -> Transaction:
        self.caller = caller

        arguments = arguments or []
        gas_price = int(gas_price)
        gas_limit = int(gas_limit)
        value = str(value or "0")

        tx = Transaction()
        tx.nonce = caller.nonce
        tx.value = value
        tx.sender = caller.address.bech32()
        tx.receiver = self.address.bech32()
        tx.gasPrice = gas_price
        tx.gasLimit = gas_limit
        tx.data = self.prepare_execute_transaction_data(function, arguments)
        tx.chainID = chain
        tx.version = version

        tx.sign(caller)
        return tx
예제 #14
0
    def deploy(self, owner, arguments, gas_price, gas_limit, value, chain,
               version) -> Transaction:
        self.owner = owner
        self.compute_address()

        arguments = arguments or []
        gas_price = int(gas_price)
        gas_limit = int(gas_limit)
        value = str(value or "0")

        tx = Transaction()
        tx.nonce = owner.nonce
        tx.value = value
        tx.sender = owner.address.bech32()
        tx.receiver = Address.zero().bech32()
        tx.gasPrice = gas_price
        tx.gasLimit = gas_limit
        tx.data = self.prepare_deploy_transaction_data(arguments)
        tx.chainID = chain
        tx.version = version

        tx.sign(owner)
        return tx
예제 #15
0
    def test_serialize_transaction_with_usernames(self):
        transaction = Transaction()
        transaction.nonce = 89
        transaction.value = "0"
        transaction.sender = "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"
        transaction.receiver = "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"
        transaction.senderUsername = "******"
        transaction.receiverUsername = "******"
        transaction.gasPrice = 1000000000
        transaction.gasLimit = 50000
        transaction.data = ""
        transaction.chainID = "local-testnet"
        transaction.version = 1

        serialized = transaction.serialize().decode()
        self.assertEqual(
            """{"nonce":89,"value":"0","receiver":"erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx","sender":"erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th","senderUsername":"******","receiverUsername":"******","gasPrice":1000000000,"gasLimit":50000,"chainID":"local-testnet","version":1}""",
            serialized)

        transaction.sign(self.alice)
        self.assertEqual(
            "1bed82c3f91c9d24f3a163e7b93a47453d70e8743201fe7d3656c0214569566a76503ef0968279ac942ca43b9c930bd26638dfb075a220ce80b058ab7bca140a",
            transaction.signature)