Skip to content

Commit 38094a6

Browse files
authored
Merge pull request #21 from ProjectLibertyLabs/add-account-id-rpc-decoder
Adds AccountId RPC decoder
2 parents 5d82fa3 + e90938f commit 38094a6

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

crypto/src/jni-crypto/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ curve25519-dalek = { version = "2.1.0", default-features = false }
1212
schnorrkel = { version = "0.9.1", features = ["preaudit_deprecated", "u64_backend"] }
1313
hex = "0.4.3"
1414

15+
# Pinned transitive dependencies
16+
proc-macro2 = { version = "=1.0.81" }
17+
unicode-ident = { version = "=1.0.12" }
18+
quote = { version = "=1.0.36" }
19+
log = { version = "=0.4.21" }
20+
1521
[dev-dependencies]
1622
hex-literal = "0.2.0"
17-
rand = { version = "0.7.3", features = ["wasm-bindgen"] }
23+
rand = { version = "0.7.3", features = ["wasm-bindgen"] }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.strategyobject.substrateclient.rpc.api;
2+
3+
import com.strategyobject.substrateclient.crypto.ss58.SS58Codec;
4+
import com.strategyobject.substrateclient.rpc.DecoderPair;
5+
import com.strategyobject.substrateclient.rpc.RpcDecoder;
6+
import com.strategyobject.substrateclient.rpc.annotation.AutoRegister;
7+
import com.strategyobject.substrateclient.transport.RpcObject;
8+
import lombok.RequiredArgsConstructor;
9+
10+
@RequiredArgsConstructor
11+
@AutoRegister(types = AccountId.class)
12+
public class AccountIdDecoder implements RpcDecoder<AccountId> {
13+
14+
@Override
15+
public AccountId decode(RpcObject value, DecoderPair<?>... decoders) {
16+
if (value.isNull()) { return null; }
17+
if (decoders != null && decoders.length > 0) throw new IllegalArgumentException();
18+
19+
return AccountId.fromBytes(SS58Codec.decode(value.asString()).getAddress());
20+
}
21+
22+
}

0 commit comments

Comments
 (0)