Skip to content

Commit cad765f

Browse files
authored
Upgrade upstream v2.0.0 rc5 (#99)
* upgrade toml and lock * upgrade some dependencies. builds now. xtrinsic fails with bad signature * panic upon invalid extrinsic with more verbose message * include transaction_version in extrinsic signature. See paritytech/substrate@ea501c2d * fix no_std test Cargo.lock * fix unit tests by moving panic and adjusting error types * fmt
1 parent 999d407 commit cad765f

File tree

12 files changed

+2248
-1019
lines changed

12 files changed

+2248
-1019
lines changed

Cargo.lock

Lines changed: 1673 additions & 566 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "substrate-api-client"
3-
version = "0.4.6-sub2.0.0-alpha.7"
3+
version = "0.4.7-sub2.0.0-rc5"
44
authors = ["Supercomputing Systems AG <[email protected]>"]
55
edition = "2018"
66

@@ -15,75 +15,75 @@ thiserror = { version = "1.0", optional =true }
1515
primitive-types = { version = "0.6.1", optional = true, features = ["codec"] }
1616

1717
[dependencies.sp-core]
18-
version = '2.0.0-alpha.7'
18+
version = '2.0.0-rc5'
1919
package = "sp-core"
2020
default-features = false
2121
features = ["full_crypto"]
2222

2323
[dependencies.codec]
2424
package = "parity-scale-codec"
2525
features = ["derive"]
26-
version = "1.3.0"
26+
version = "1.3.1"
2727
default-features = false
2828

2929
[dependencies.runtime_io]
30-
version = '2.0.0-alpha.7'
30+
version = '2.0.0-rc5'
3131
package = "sp-io"
3232
default-features=false
3333

3434
[dependencies.metadata]
35-
version = '11.0.0-alpha.7'
35+
version = '11.0.0-rc5'
3636
package = "frame-metadata"
3737
default-features=false
3838

3939
[dependencies.sp-version]
40-
version = '2.0.0-alpha.7'
40+
version = '2.0.0-rc5'
4141
package = "sp-version"
4242
default-features=false
4343

4444
[dependencies.balances]
45-
version = '2.0.0-alpha.7'
45+
version = '2.0.0-rc5'
4646
package = "pallet-balances"
4747
default-features=false
4848

4949
[dependencies.system]
50-
version = '2.0.0-alpha.7'
50+
version = '2.0.0-rc5'
5151
package = "frame-system"
5252
default-features=false
5353

5454
[dependencies.sp-runtime]
55-
version = '2.0.0-alpha.7'
55+
version = '2.0.0-rc5'
5656
package = "sp-runtime"
5757
default-features=false
5858

5959
[dependencies.support]
60-
version = '2.0.0-alpha.7'
60+
version = '2.0.0-rc5'
6161
package = "frame-support"
6262
default-features=false
6363

6464
[dependencies.sp-std]
65-
version = '2.0.0-alpha.7'
65+
version = '2.0.0-rc5'
6666
package = "sp-std"
6767
default-features = false
6868

6969
[dependencies.sc-rpc-api]
70-
version = '0.8.0-alpha.7'
70+
version = '0.8.0-rc5'
7171
optional = true
7272

7373
[dev-dependencies.node_template_runtime]
7474
git = "https://github.com/scs/substrate-api-client-test-node"
75-
tag = 'v2.0.0-alpha.7'
75+
tag = 'v2.0.0-rc5'
7676
package = "node-template-runtime"
7777

7878
[dev-dependencies]
7979
wabt = "0.9.0"
8080

8181
[dev-dependencies.contracts]
82-
version = '2.0.0-alpha.7'
82+
version = '2.0.0-rc5'
8383
package = "pallet-contracts"
8484

8585
[dev-dependencies.keyring]
86-
version = '2.0.0-alpha.7'
86+
version = '2.0.0-rc5'
8787
package = "sp-keyring"
8888

8989
[dev-dependencies.clap]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# substrate-api-client
22

3-
![badge](https://img.shields.io/badge/substrate-2.0.0--alpha.7-success)
3+
![badge](https://img.shields.io/badge/substrate-2.0.0--rc5-success)
44

55
<p align="center">
66
<img src=./web3_foundation_grants_badge_black.svg width = 400>

src/examples/example_benchmark_bulk_xt.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ fn main() {
5555
Era::Immortal,
5656
api.genesis_hash,
5757
api.genesis_hash,
58-
api.runtime_version.spec_version
58+
api.runtime_version.spec_version,
59+
api.runtime_version.transaction_version
5960
);
6061
// send and watch extrinsic until finalized
6162
println!("sending extrinsic with nonce {}", nonce);

src/examples/example_compose_extrinsic_offline.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ fn main() {
5656
Era::mortal(period, h.number.into()),
5757
api.genesis_hash,
5858
head,
59-
api.runtime_version.spec_version
59+
api.runtime_version.spec_version,
60+
api.runtime_version.transaction_version
6061
);
6162

6263
println!("[+] Composed Extrinsic:\n {:?}\n", xt);

src/extrinsic/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ macro_rules! compose_extrinsic_offline {
6767
$era: expr,
6868
$genesis_hash: expr,
6969
$genesis_or_current_hash: expr,
70-
$runtime_spec_version: expr) => {{
70+
$runtime_spec_version: expr,
71+
$transaction_version: expr) => {{
7172
use sp_runtime::generic::Era;
7273
use $crate::extrinsic::xt_primitives::*;
7374
let extra = GenericExtra::new($era, $nonce);
@@ -76,12 +77,12 @@ macro_rules! compose_extrinsic_offline {
7677
extra.clone(),
7778
(
7879
$runtime_spec_version,
80+
$transaction_version,
7981
$genesis_hash,
8082
$genesis_or_current_hash,
8183
(),
8284
(),
8385
(),
84-
(),
8586
),
8687
);
8788

@@ -131,7 +132,8 @@ macro_rules! compose_extrinsic {
131132
Era::Immortal,
132133
$api.genesis_hash,
133134
$api.genesis_hash,
134-
$api.runtime_version.spec_version
135+
$api.runtime_version.spec_version,
136+
$api.runtime_version.transaction_version
135137
)
136138
} else {
137139
UncheckedExtrinsicV4 {

src/extrinsic/xt_primitives.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Default for GenericExtra {
5555

5656
/// additionalSigned fields of the respective SignedExtra fields.
5757
/// Order is the same as declared in the extra.
58-
pub type AdditionalSigned = (u32, H256, H256, (), (), (), ());
58+
pub type AdditionalSigned = (u32, u32, H256, H256, (), (), ());
5959

6060
#[derive(Encode, Clone)]
6161
pub struct SignedPayload<Call>((Call, GenericExtra, AdditionalSigned));

src/rpc/client.rs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn on_extrinsic_msg_until_finalized(
101101
debug!("got msg {}", retstr);
102102
match parse_status(retstr) {
103103
(XtStatus::Finalized, val) => end_process(out, result, val),
104-
(XtStatus::Error, e) => end_process(out, result, e),
104+
(XtStatus::Error, e) => panic!(e),
105105
(XtStatus::Future, _) => {
106106
warn!("extrinsic has 'future' status. aborting");
107107
end_process(out, result, None);
@@ -122,7 +122,7 @@ pub fn on_extrinsic_msg_until_in_block(
122122
(XtStatus::Finalized, val) => end_process(out, result, val),
123123
(XtStatus::InBlock, val) => end_process(out, result, val),
124124
(XtStatus::Future, _) => end_process(out, result, None),
125-
(XtStatus::Error, _) => end_process(out, result, None),
125+
(XtStatus::Error, e) => panic!(e),
126126
_ => (),
127127
};
128128
Ok(())
@@ -139,7 +139,7 @@ pub fn on_extrinsic_msg_until_broadcast(
139139
(XtStatus::Finalized, val) => end_process(out, result, val),
140140
(XtStatus::Broadcast, _) => end_process(out, result, None),
141141
(XtStatus::Future, _) => end_process(out, result, None),
142-
(XtStatus::Error, _) => end_process(out, result, None),
142+
(XtStatus::Error, e) => panic!(e),
143143
_ => (),
144144
};
145145
Ok(())
@@ -156,7 +156,7 @@ pub fn on_extrinsic_msg_until_ready(
156156
(XtStatus::Finalized, val) => end_process(out, result, val),
157157
(XtStatus::Ready, _) => end_process(out, result, None),
158158
(XtStatus::Future, _) => end_process(out, result, None),
159-
(XtStatus::Error, e) => end_process(out, result, e),
159+
(XtStatus::Error, e) => panic!(e),
160160
_ => (),
161161
};
162162
Ok(())
@@ -175,12 +175,18 @@ fn parse_status(msg: &str) -> (XtStatus, Option<String>) {
175175
match value["error"].as_object() {
176176
Some(obj) => {
177177
let error_message = obj.get("message").unwrap().as_str().unwrap().to_owned();
178-
error!(
179-
"extrinsic error code {}: {}",
180-
obj.get("code").unwrap().as_u64().unwrap(),
181-
error_message
182-
);
183-
(XtStatus::Error, Some(error_message))
178+
let code = obj.get("code").unwrap().as_i64().unwrap();
179+
let details = match obj.get("data") {
180+
Some(d) => d.as_str().unwrap().to_owned(),
181+
None => "".to_string(),
182+
};
183+
(
184+
XtStatus::Error,
185+
Some(format!(
186+
"extrinsic error code {}: {}: {}",
187+
code, error_message, details
188+
)),
189+
)
184190
}
185191
None => match value["params"]["result"].as_object() {
186192
Some(obj) => {
@@ -261,21 +267,27 @@ mod tests {
261267
let msg = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32700,\"message\":\"Parse error\"},\"id\":null}";
262268
assert_eq!(
263269
parse_status(msg),
264-
(XtStatus::Error, Some("Parse error".into()))
270+
(
271+
XtStatus::Error,
272+
Some("extrinsic error code -32700: Parse error: ".into())
273+
)
265274
);
266275

267-
let msg = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":1010,\"message\":\"Invalid Transaction\",\"data\":0},\"id\":\"4\"}";
276+
let msg = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":1010,\"message\":\"Invalid Transaction\",\"data\":\"Bad Signature\"},\"id\":\"4\"}";
268277
assert_eq!(
269278
parse_status(msg),
270-
(XtStatus::Error, Some("Invalid Transaction".into()))
279+
(
280+
XtStatus::Error,
281+
Some("extrinsic error code 1010: Invalid Transaction: Bad Signature".into())
282+
)
271283
);
272284

273285
let msg = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":1001,\"message\":\"Extrinsic has invalid format.\"},\"id\":\"0\"}";
274286
assert_eq!(
275287
parse_status(msg),
276288
(
277289
XtStatus::Error,
278-
Some("Extrinsic has invalid format.".into())
290+
Some("extrinsic error code 1001: Extrinsic has invalid format.: ".into())
279291
)
280292
);
281293

@@ -285,7 +297,7 @@ mod tests {
285297
(
286298
XtStatus::Error,
287299
Some(
288-
"Verification Error: Execution(Wasmi(Trap(Trap { kind: Unreachable })))".into()
300+
"extrinsic error code 1002: Verification Error: Execution(Wasmi(Trap(Trap { kind: Unreachable }))): RuntimeApi(\"Execution(Wasmi(Trap(Trap { kind: Unreachable })))\")".into()
289301
)
290302
)
291303
);

0 commit comments

Comments
 (0)