Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix transaction process status #69

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
114 changes: 114 additions & 0 deletions examples/contracts/issue-esdt-with-contract/issue-with-contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import base64
import sys
import time
from pathlib import Path

from multiversx_sdk_core import TokenComputer, AddressFactory, Address
from multiversx_sdk_core.transaction_factories import SmartContractTransactionsFactory, TransactionsFactoryConfig
from multiversx_sdk_network_providers import ProxyNetworkProvider
from multiversx_sdk_network_providers.transactions import TransactionOnNetwork
from multiversx_sdk_wallet import UserPEM

SIMULATOR_URL = "http://localhost:8085"
GENERATE_BLOCKS_URL = f"{SIMULATOR_URL}/simulator/generate-blocks"


def main():
# create a network provider
provider = ProxyNetworkProvider(SIMULATOR_URL)

pem = UserPEM.from_file(Path("../../wallets/wallet.pem"))

# call proxy faucet
address = pem.public_key.to_address("erd")
data = {"receiver": f"{address.to_bech32()}"}
provider.do_post(f"{SIMULATOR_URL}/transaction/send-user-funds", data)

# generate 20 blocks to pass an epoch and the smart contract deploys to be enabled
provider.do_post(f"{GENERATE_BLOCKS_URL}/20", {})

config = TransactionsFactoryConfig(provider.get_network_config().chain_id)

sc_factory = SmartContractTransactionsFactory(config, TokenComputer())

bytecode = Path("./contract.wasm").read_bytes()
deploy_transaction = sc_factory.create_transaction_for_deploy(
sender=address,
bytecode=bytecode,
arguments=[],
gas_limit=10000000,
is_upgradeable=True,
is_readable=True,
is_payable=True,
is_payable_by_sc=True
)

# set nonce
deploy_transaction.nonce = provider.get_account(address).nonce
deploy_transaction.signature = b"dummy"

# send transaction
tx_hash = provider.send_transaction(deploy_transaction)
print(f"deploy tx hash: {tx_hash}")

time.sleep(0.5)

# execute 1 block
provider.do_post(f"{GENERATE_BLOCKS_URL}/1", {})

# get transaction with status
tx_from_network = provider.get_transaction(tx_hash, with_process_status=True)

# verify transaction status and account balance
if not tx_from_network.status.is_successful():
sys.exit(f"transaction status is not correct, status received->{tx_from_network.status}")

contract_address = extract_contract_address(tx_from_network)
call_transaction = sc_factory.create_transaction_for_execute(
sender=address,
contract=contract_address,
function="issue",
gas_limit=100000000,
arguments=[]
)

call_transaction.amount = 10000000000000000
call_transaction.nonce = provider.get_account(address).nonce
call_transaction.signature = b"dummy"

# send transaction
tx_hash = provider.send_transaction(call_transaction)
print(f"sc call tx hash: {tx_hash}")

time.sleep(0.5)

provider.do_post(f"{GENERATE_BLOCKS_URL}/3", {})

status = get_processed_status(provider, tx_hash)
if status != "pending":
sys.exit(f"incorrect status of transaction: expected->pending, received->{status}")

provider.do_post(f"{GENERATE_BLOCKS_URL}/3", {})
status = get_processed_status(provider, tx_hash)
if status != "fail":
sys.exit(f"incorrect status of transaction: expected->fail, received->{status}")


def get_processed_status(provider, tx_hash):
response = provider.do_get(f"{SIMULATOR_URL}/transaction/{tx_hash}/process-status")

return response.get("status")


def extract_contract_address(tx: TransactionOnNetwork) -> Address:
factory = AddressFactory("erd")
for event in tx.logs.events:
if event.identifier != "SCDeploy":
continue

return factory.create_from_hex(event.topics[0].hex())


if __name__ == "__main__":
main()

28 changes: 14 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ go 1.20

require (
github.com/gin-gonic/gin v1.9.1
github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6
github.com/multiversx/mx-chain-go v1.7.14-0.20240725074334-768ec0db4f5e
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775
github.com/multiversx/mx-chain-proxy-go v1.1.50-0.20240725074538-9a6b0bb68036
github.com/multiversx/mx-chain-core-go v1.2.21
github.com/multiversx/mx-chain-go v1.7.17-0.20240805122458-792f6a7ac100
github.com/multiversx/mx-chain-logger-go v1.0.15
github.com/multiversx/mx-chain-proxy-go v1.1.50-0.20240806090144-97c410603ea5
github.com/pelletier/go-toml v1.9.3
github.com/stretchr/testify v1.8.4
github.com/urfave/cli v1.22.10
Expand Down Expand Up @@ -116,16 +116,16 @@ require (
github.com/multiformats/go-multistream v0.4.1 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/multiversx/concurrent-map v0.1.4 // indirect
github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240725071304-ebce652ff65d // indirect
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f // indirect
github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca // indirect
github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240725072925-89c927c8b6a6 // indirect
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf // indirect
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240725072715-8806f1301087 // indirect
github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240725073737-3f682a6c59db // indirect
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240725073104-85ec99cb9260 // indirect
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240725073322-952f3197e2e2 // indirect
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240725073616-3b96f06509cf // indirect
github.com/multiversx/mx-chain-communication-go v1.1.0 // indirect
github.com/multiversx/mx-chain-crypto-go v1.2.12 // indirect
github.com/multiversx/mx-chain-es-indexer-go v1.7.4 // indirect
github.com/multiversx/mx-chain-scenario-go v1.4.4 // indirect
github.com/multiversx/mx-chain-storage-go v1.0.16 // indirect
github.com/multiversx/mx-chain-vm-common-go v1.5.13 // indirect
github.com/multiversx/mx-chain-vm-go v1.5.30 // indirect
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 // indirect
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 // indirect
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 // indirect
github.com/multiversx/mx-components-big-int v1.0.0 // indirect
github.com/onsi/ginkgo/v2 v2.11.0 // indirect
github.com/onsi/gomega v1.27.10 // indirect
Expand Down
56 changes: 28 additions & 28 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -393,34 +393,34 @@ github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/n
github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU=
github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUYwbO0993uPI=
github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o=
github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240725071304-ebce652ff65d h1:grQCJW4DCvvIQ6q84sy23oAp8XQ8Dxr3Js8aoh+m99M=
github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240725071304-ebce652ff65d/go.mod h1:hFGM+O7rt+gWXSHFoRjC3/oN0OJfPfeFAxqXIac5UdQ=
github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6 h1:Q7uUjTYTrt8Mw9oq5JWPv+WHhpxHTv6lhZZlhPuNcoQ=
github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f h1:jydjrmVFvSllBOTppveOAkLITpOYKk0kma5z0bfDImI=
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f/go.mod h1:9aSp//uBSvqFdzh4gvYISraoruhr1FCTXgPQalQ687k=
github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca h1:9b2yFAarWDG/jTYePv0UqNWQ9gxeSZy9mGxtd8dFj2Y=
github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca/go.mod h1:bHPP5zerhmbRfVcbfXgpMPUaTKMrK6gGi+rRbw0BpDE=
github.com/multiversx/mx-chain-go v1.7.14-0.20240725074334-768ec0db4f5e h1:BE2MM87F6/klNNd/smSgmbADs1tR5I3jqtSlics8srM=
github.com/multiversx/mx-chain-go v1.7.14-0.20240725074334-768ec0db4f5e/go.mod h1:EH9tTTZaHV54MyISu+dJMdUMoo64RwaQwWIPDiCzDjc=
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775 h1:a8LOfz3p4MQfRtbF00rGDAJiebziwtSfVmBHIaHBDdY=
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775/go.mod h1:owPYyrK7RcsLx9eOCAZQ22fIyW6BE7ttJr4XIhFIbQw=
github.com/multiversx/mx-chain-proxy-go v1.1.50-0.20240725074538-9a6b0bb68036 h1:vZKROgtOqZyObGyd/160L5mYnardS+HdqcOlFd9ASx4=
github.com/multiversx/mx-chain-proxy-go v1.1.50-0.20240725074538-9a6b0bb68036/go.mod h1:rinr3/T4mo0sc7x5vy7hIPnSUQh+c+rHAJ/s2x2hF5o=
github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240725072925-89c927c8b6a6 h1:QGQjSlPix5nBtCkcdyKo0b2sRYXwYF/GBtccOqDbU6Y=
github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240725072925-89c927c8b6a6/go.mod h1:MvJiMtuyGq43aS9eOgF+xQUWk0hYxvCQqLrT77bhBaE=
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf h1:L9K7Xzq5SZz6k55R7HrafiRcU+c8/PqozJxys65G4bI=
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf/go.mod h1:ptvW/8r6bam55mVpeVZbyvvvydYM0DQwcPOH0W4Xyx8=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240725072715-8806f1301087 h1:ovxs8X50iBL9TOkn0qHrkuXrBS1Y/EWfQOYmFEaXRNs=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240725072715-8806f1301087/go.mod h1:nNGN+rdLRN8Nd6OhFGrkEZS5Ipj5IQCvFT0L/iQbOpU=
github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240725073737-3f682a6c59db h1:ZSvHaMsoL0hNfaVBsBZskUdMEaKu+Fdrx3KZrSBbkio=
github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240725073737-3f682a6c59db/go.mod h1:CFOSVrsHOzaO5YX2L/wyjP76L+BE/9rh+SereQV3pHA=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240725073104-85ec99cb9260 h1:Ny3s7dw2oF6AVq4kZYmhNYWvAuLEbd48JPPIC6tFzOA=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240725073104-85ec99cb9260/go.mod h1:NFRX6UrkBMb28HFKZyKwH894uxfrZyfuFqMF1KBVqFw=
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240725073322-952f3197e2e2 h1:TM45+UXZV5DYOHlbGiHyQm44hOlBid8g9qfvYqopILs=
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240725073322-952f3197e2e2/go.mod h1:Ntfq9tUV3I5k6SS/OpW4HSO6AlZbs/xxgB2poOuc2pg=
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240725073616-3b96f06509cf h1:axwaSswcaw8pituLVAu4IWlGNtYwXvUMYy+MGPwmxuY=
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240725073616-3b96f06509cf/go.mod h1:2TjMTiVFkh5wFImEEFZl+k5MU8bh2287btJuVCR3sL0=
github.com/multiversx/mx-chain-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE=
github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM=
github.com/multiversx/mx-chain-core-go v1.2.21 h1:+XVKznPTlUU5EFS1A8chtS8fStW60upRIyF4Pgml19I=
github.com/multiversx/mx-chain-core-go v1.2.21/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk=
github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4=
github.com/multiversx/mx-chain-es-indexer-go v1.7.4 h1:SjJk9G9SN8baz0sFIU2jymYCfx3XiikGEB2wW0jwvfw=
github.com/multiversx/mx-chain-es-indexer-go v1.7.4/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4=
github.com/multiversx/mx-chain-go v1.7.17-0.20240805122458-792f6a7ac100 h1:cbxogSpDqz6m8/EqpJR9QIDH1oUwXtkT6Hgn5IhibG4=
github.com/multiversx/mx-chain-go v1.7.17-0.20240805122458-792f6a7ac100/go.mod h1:OqhNS0/0bLSQICGQU+f7/i9BXO4xwmOE1ZQlRhABD7I=
github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc=
github.com/multiversx/mx-chain-logger-go v1.0.15/go.mod h1:t3PRKaWB1M+i6gUfD27KXgzLJJC+mAQiN+FLlL1yoGQ=
github.com/multiversx/mx-chain-proxy-go v1.1.50-0.20240806090144-97c410603ea5 h1:TIztZ/g2aehAIZGKhM1EsVsNngGZfW4AU6+jE1oKqNA=
github.com/multiversx/mx-chain-proxy-go v1.1.50-0.20240806090144-97c410603ea5/go.mod h1:Ax+80b1qynepkZSxrz8QB3AO00JAL3svaLasMTE6Lh0=
github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFzHeruelESfpTlf460=
github.com/multiversx/mx-chain-scenario-go v1.4.4/go.mod h1:kI+TWR3oIEgUkbwkHCPo2CQ3VjIge+ezGTibiSGwMxo=
github.com/multiversx/mx-chain-storage-go v1.0.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs=
github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI=
github.com/multiversx/mx-chain-vm-common-go v1.5.13 h1:ymnIHJW4Z4mFa0hZzla4fozkF30vjH5O1q+Y7Ftc+pQ=
github.com/multiversx/mx-chain-vm-common-go v1.5.13/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ=
github.com/multiversx/mx-chain-vm-go v1.5.30 h1:CXBQF3o+dai4nx2qYfMIACva+6SqPO5fZjZtVq72RTI=
github.com/multiversx/mx-chain-vm-go v1.5.30/go.mod h1:iq6sCPweoHC9Fx56uf8buPrqlGVGJKUMRFxTunzjvys=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI=
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc=
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69/go.mod h1:msY3zaS+K+R10ypqQs/jke6xdNAJzS38PGIaeJj2zhg=
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 h1:/fYx4ClVPU48pTKh2qk4QVlve0xjjDpvzOakjFUtXJ8=
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98/go.mod h1:4vqG8bSmufZx263DMrmr8OLbO6q6//VPC4W9PxZLB5Q=
github.com/multiversx/mx-components-big-int v1.0.0 h1:Wkr8lSzK2nDqixOrrBa47VNuqdhV1m/aJhaP1EMaiS8=
github.com/multiversx/mx-components-big-int v1.0.0/go.mod h1:maIEMgHlNE2u78JaDD0oLzri+ShgU4okHfzP3LWGdQM=
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo=
Expand Down
3 changes: 3 additions & 0 deletions scripts/run-examples/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ run_python_script ../../examples/generateBlocks epoch-reached.py

# run set state examples
run_python_script ../../examples/setState code-metadata.py

# run deploy with issue esdt
run_python_script ../../examples/contracts/issue-esdt-with-contract issue-with-contract.py
Loading