Skip to content

Add ability to exit on InBlock and Broadcast status for send_extrinsic #72

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

Merged
merged 1 commit into from
May 4, 2020

Conversation

hoani
Copy link
Contributor

@hoani hoani commented May 1, 2020

send_extrinsic can now take XtStatus::InBlock and XtStatus::Broadcast as statuses to exit on.

Changes

  • Add XtStatus::InBlock and XtStatus::Broadcast cases to send_extrinsic
  • Add send_extrinsic_and_wait_until... functions for InBlock and Broadcast to the rpc module
  • Implement on_extrinsic_msg_until... functions in the rpc client
  • Add tests against parse_status for Inblock and `Broadcast

Testing against a substrate node

InBlock

Modified example_generic_extrinsic (ln 51) to:

let tx_hash = api
    .send_extrinsic(xt.hex_encode(), XtStatus::InBlock)
    .unwrap();
println!("[+] Transaction got in block. Hash: {:?}", tx_hash);

Console output using RUST_LOG=debug cargo run --example example_generic_extrinsic:

...
2020-05-01T08:11:06Z DEBUG substrate_api_client::rpc::client] got msg {"jsonrpc":"2.0","method":"author_extrinsicUpdate","params":{"result":{"inBlock":"0x1377c2c36f2776c80d903895b74dfd726ad1d1e599ac2ba7f991d5f08abd69f5"},"subscription":6}}
[2020-05-01T08:11:06Z INFO  substrate_api_client::rpc::client] inBlock: String("0x1377c2c36f2776c80d903895b74dfd726ad1d1e599ac2ba7f991d5f08abd69f5")
[2020-05-01T08:11:06Z INFO  substrate_api_client] inBlock: "0x1377c2c36f2776c80d903895b74dfd726ad1d1e599ac2ba7f991d5f08abd69f5"
[+] Transaction got in block. Hash: Some(0x1377c2c36f2776c80d903895b74dfd726ad1d1e599ac2ba7f991d5f08abd69f5)

Broadcast

Modified example_generic_extrinsic (ln 51) to:

let _ = api
   .send_extrinsic(xt.hex_encode(), XtStatus::Broadcast)
   .unwrap();

Console output using RUST_LOG=debug cargo run --example example_generic_extrinsic:

...
[2020-05-01T08:39:24Z INFO  substrate_api_client::rpc::client] inBlock: String("0x46ab184e79d23c7e30a0589c825d6f1148d5b9c2a9907bc1e5b0bc6239c74042")
...             
[2020-05-01T08:29:55Z DEBUG substrate_api_client::rpc::client] got msg {"jsonrpc":"2.0","method":"author_extrinsicUpdate","params":{"result":{"finalized":"0x91f73815187eb639de5ee2a7ae29f695dc335e0a8586cd6a4598a15155ceaf06"},"subscription":8}}
[2020-05-01T08:29:55Z INFO  substrate_api_client::rpc::client] finalized: String("0x91f73815187eb639de5ee2a7ae29f695dc335e0a8586cd6a4598a15155ceaf06")
[2020-05-01T08:29:55Z INFO  substrate_api_client] broadcast: "0x91f73815187eb639de5ee2a7ae29f695dc335e0a8586cd6a4598a15155ceaf06"

This showed that when waiting for broadcast, the broadcast status never appeared, so it just stopped on finalised instead. I think the reason for this is that I was only running a single validator node in my test, so there was nowhere for the node to broadcast the transaction.

Addresses #65

@brenzi
Copy link
Contributor

brenzi commented May 2, 2020

Thanks @hoani. I've tested the code and it works. Also your observation on Broadcast is probably correct.

It is a pity that you didn't wait until we assigned this task to you. To be fair, we need to give the assigned dev a chance to fix his PR. I hope you understand that we prefer a clear process and only one PR to review. Would this be of interest to you?

@hoani
Copy link
Contributor Author

hoani commented May 3, 2020

Hey @brenzi - my apologies, this was the first bounty I have participated in. I completely respect that the fair thing to do is to let the assigned dev finish their work.
Unfortunately, I am a little busy at the moment on another project, and the IPFS project looks a little too big for me to split my time on it. Thank you for asking though!
I really like that you are building a rust API client for substrate; hopefully we can collaborate again later 😄

@hoani hoani closed this May 3, 2020
@brenzi brenzi reopened this May 4, 2020
@brenzi brenzi merged commit 129ec67 into scs:master May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants