Skip to content

Commit 48d8852

Browse files
authored
Upgrade account balances to new RPCs (#20)
* fix: Account balances * Version bump
1 parent 73133bd commit 48d8852

File tree

3 files changed

+84
-79
lines changed

3 files changed

+84
-79
lines changed

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "polkadot-rpc-proxy",
3-
"version": "0.1.9",
3+
"version": "0.1.10",
44
"description": "",
55
"main": "index.js",
66
"scripts": {
@@ -11,10 +11,10 @@
1111
"author": "",
1212
"license": "GPL-3.0-or-later",
1313
"dependencies": {
14-
"@polkadot/api": "1.6.2",
15-
"@polkadot/metadata": "1.6.2",
16-
"@polkadot/rpc-provider": "1.6.2",
17-
"@polkadot/types": "1.6.2",
14+
"@polkadot/api": "1.7.1",
15+
"@polkadot/metadata": "1.7.1",
16+
"@polkadot/rpc-provider": "1.7.1",
17+
"@polkadot/types": "1.7.1",
1818
"@types/express": "^4.17.2",
1919
"express": "^4.17.1",
2020
"typescript": "^3.8.2"

src/ApiHandler.ts

+25-8
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,37 @@ export default class ApiHandler {
126126
async fetchBalance(hash: BlockHash, address: string) {
127127
const api = await this.ensureMeta(hash);
128128

129-
const [header, free, reserved, locks, nonce] = await Promise.all([
129+
const [header, account, locks, sysAccount] = await Promise.all([
130130
api.rpc.chain.getHeader(hash),
131-
api.query.balances.freeBalance.at(hash, address),
132-
api.query.balances.reservedBalance.at(hash, address),
131+
api.query.balances.account.at(hash, address),
133132
api.query.balances.locks.at(hash, address),
134-
api.query.system.accountNonce.at(hash, address),
133+
api.query.system.account.at(hash, address),
135134
]);
136135

137136
const at = {
138137
hash,
139138
height: (header as any).number, // TODO: fix this nasty obvious type erasure
140139
};
141140

142-
return { at, nonce, free, reserved, locks };
141+
if (account && locks && sysAccount) {
142+
const { free, reserved, miscFrozen, feeFrozen } = account;
143+
const { nonce } = sysAccount;
144+
145+
return {
146+
at,
147+
nonce,
148+
free,
149+
reserved,
150+
miscFrozen,
151+
feeFrozen,
152+
locks,
153+
};
154+
} else {
155+
return {
156+
at,
157+
error: "Account not found",
158+
};
159+
}
143160
}
144161

145162
async fetchMetadata(hash: BlockHash) {
@@ -165,9 +182,9 @@ export default class ApiHandler {
165182
const runtimeVersion = await api.rpc.state.getRuntimeVersion(hash);
166183
const blockSpecVersion = runtimeVersion.specVersion;
167184

168-
// swap metadata if spec version is different
169-
if (!this.specVersion.eq(blockSpecVersion)) {
170-
this.specVersion = blockSpecVersion;
185+
// swap metadata if spec version is different
186+
if (!this.specVersion.eq(blockSpecVersion)) {
187+
this.specVersion = blockSpecVersion;
171188
const meta = await api.rpc.state.getMetadata(hash);
172189
const chain = await api.rpc.system.chain();
173190

yarn.lock

+54-66
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,54 @@
22
# yarn lockfile v1
33

44

5-
"@babel/runtime@^7.8.4":
6-
version "7.8.4"
7-
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.8.4.tgz#d79f5a2040f7caa24d53e563aad49cbc05581308"
8-
integrity sha512-neAp3zt80trRVBI1x0azq6c57aNBqYZH8KhMm3TaB7wEI5Q4A2SHfBHE8w9gOhI/lrqxtEbXZgQIrHP+wvSGwQ==
9-
dependencies:
10-
regenerator-runtime "^0.13.2"
11-
125
"@babel/runtime@^7.8.7":
136
version "7.8.7"
147
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.8.7.tgz#8fefce9802db54881ba59f90bb28719b4996324d"
158
integrity sha512-+AATMUFppJDw6aiR5NVPHqIQBlV/Pj8wY/EZH+lmvRdUo9xBaz/rF3alAwFJQavvKfeOlPE7oaaDHVbcySbCsg==
169
dependencies:
1710
regenerator-runtime "^0.13.4"
1811

19-
"@polkadot/api-derive@1.6.2":
20-
version "1.6.2"
21-
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-1.6.2.tgz#6f6b327b854b9a5624130bdfca6319b91a2ffe2d"
22-
integrity sha512-x0LA+Jh1GV9yjMYflE0G7PN87Bglm6fu3KepJdxg4FLja4ruYygvOKlprlEynOqW7bEEKba01cB2t7B3ksPzFw==
12+
"@polkadot/api-derive@1.7.1":
13+
version "1.7.1"
14+
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-1.7.1.tgz#17446854462886e9782e68cbfb6f86dc0405a830"
15+
integrity sha512-kSJ9K6RQH8fuyUL+51PtuVjBhwUW+Cwm15fBzX0qWrZHqPzeBnZBdZFCJ8gGP61Olfl7u6OQeChhujL5NGwCHA==
2316
dependencies:
24-
"@babel/runtime" "^7.8.4"
25-
"@polkadot/api" "1.6.2"
26-
"@polkadot/rpc-core" "1.6.2"
27-
"@polkadot/rpc-provider" "1.6.2"
28-
"@polkadot/types" "1.6.2"
17+
"@babel/runtime" "^7.8.7"
18+
"@polkadot/api" "1.7.1"
19+
"@polkadot/rpc-core" "1.7.1"
20+
"@polkadot/rpc-provider" "1.7.1"
21+
"@polkadot/types" "1.7.1"
2922
"@polkadot/util" "^2.6.2"
3023
"@polkadot/util-crypto" "^2.6.2"
3124
bn.js "^5.1.1"
3225
memoizee "^0.4.14"
3326
rxjs "^6.5.4"
3427

35-
"@polkadot/api@1.6.2":
36-
version "1.6.2"
37-
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-1.6.2.tgz#d9ec9a292b163c6f33c2b54974ec6733287a6595"
38-
integrity sha512-ZTOOBzfyt1ZWmsvNhMXjcu+4ASSbd3obgma88VkOF7JcF77DoLdFfESqzOoj3xViOOH+yqqZ1bMNoDr1QmZfYg==
28+
"@polkadot/api@1.7.1":
29+
version "1.7.1"
30+
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-1.7.1.tgz#89470ca40bc64e355d691e75940f92f6e444aa1b"
31+
integrity sha512-axrsxpXbM1K3H6FzSWYQKaVlKyqXheZVId1grOKwX3ZA/DB/mSr1YFXqZt8UNgzJDf8LH3VOyWHOOcmxWyi7nw==
3932
dependencies:
40-
"@babel/runtime" "^7.8.4"
41-
"@polkadot/api-derive" "1.6.2"
33+
"@babel/runtime" "^7.8.7"
34+
"@polkadot/api-derive" "1.7.1"
4235
"@polkadot/keyring" "^2.6.2"
43-
"@polkadot/metadata" "1.6.2"
44-
"@polkadot/rpc-core" "1.6.2"
45-
"@polkadot/rpc-provider" "1.6.2"
46-
"@polkadot/types" "1.6.2"
36+
"@polkadot/metadata" "1.7.1"
37+
"@polkadot/rpc-core" "1.7.1"
38+
"@polkadot/rpc-provider" "1.7.1"
39+
"@polkadot/types" "1.7.1"
4740
"@polkadot/util" "^2.6.2"
4841
"@polkadot/util-crypto" "^2.6.2"
4942
bn.js "^5.1.1"
5043
eventemitter3 "^4.0.0"
5144
rxjs "^6.5.4"
5245

53-
"@polkadot/jsonrpc@1.6.2":
54-
version "1.6.2"
55-
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-1.6.2.tgz#57c057b9d649782753621afa0390ed5a86b9b480"
56-
integrity sha512-hYzyT0QsUzLBb0JUtzAfp0XPKuSJnd/RnpOpVf5yZ9lk1Z+sqpe9z1LsutAPWZtUhFNtUhUfxDOSrGWu28XKhg==
46+
"@polkadot/jsonrpc@1.7.1":
47+
version "1.7.1"
48+
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-1.7.1.tgz#eb5a07415e56311cc0dbe03eeca28060e49b3d30"
49+
integrity sha512-tOniIG97p4QYTsKlRK10UTbV8EFBAlY/VeW2+vQqItY/8jsDHvExF7Wzhbxs1pRYXILaVaqGMxaXXEjoMw6Xxg==
5750
dependencies:
58-
"@babel/runtime" "^7.8.4"
59-
"@polkadot/types" "1.6.2"
51+
"@babel/runtime" "^7.8.7"
52+
"@polkadot/types" "1.7.1"
6053
"@polkadot/util" "^2.6.2"
6154

6255
"@polkadot/keyring@^2.6.2":
@@ -68,54 +61,54 @@
6861
"@polkadot/util" "2.6.2"
6962
"@polkadot/util-crypto" "2.6.2"
7063

71-
"@polkadot/metadata@1.6.2":
72-
version "1.6.2"
73-
resolved "https://registry.yarnpkg.com/@polkadot/metadata/-/metadata-1.6.2.tgz#38ef3c95209485bfcc9da9258f53e4c3da9510a3"
74-
integrity sha512-iFolXhI83E8s1Ac2RWV0ws2NL41phZSL2roscSFWsi4wUITg8h71o7W6Gp5olWeXvENraCga2Uei4+1AvvFsQg==
64+
"@polkadot/metadata@1.7.1":
65+
version "1.7.1"
66+
resolved "https://registry.yarnpkg.com/@polkadot/metadata/-/metadata-1.7.1.tgz#47878d714a0d4898a17eac74e72131140680eec9"
67+
integrity sha512-We5eaUwuBNa4Q/shLpEtwUoTZvYMQgpZPW5N/JRoitkJBHJiHvt12IR8JgQnB5wrDNoJ8f97kVOv1eeXTzhn4g==
7568
dependencies:
76-
"@babel/runtime" "^7.8.4"
77-
"@polkadot/types" "1.6.2"
69+
"@babel/runtime" "^7.8.7"
70+
"@polkadot/types" "1.7.1"
7871
"@polkadot/util" "^2.6.2"
7972
"@polkadot/util-crypto" "^2.6.2"
8073
bn.js "^5.1.1"
8174

82-
"@polkadot/rpc-core@1.6.2":
83-
version "1.6.2"
84-
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-1.6.2.tgz#4ea68dcfd29ea749d92a968abec3ba738aae4774"
85-
integrity sha512-GZeXwx3wzpS4TPEE9SjqaawmMGmB8lrvOysS1F8trRBQ278H6xt/oGS9PiATZ0Tkv4pdGPMZvStQFYaIK31Rcg==
75+
"@polkadot/rpc-core@1.7.1":
76+
version "1.7.1"
77+
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-1.7.1.tgz#ad90b330b9edef34035cd3ba755da2e0f6dc512d"
78+
integrity sha512-et5sdEJkIgU5l/nU5o5JwvuIAYz9HDYLxj+VNGIwA7ACcG+OWb/sDtBELmlYGCXmzKnMgW5aq/Fj2+Wgvj34PA==
8679
dependencies:
87-
"@babel/runtime" "^7.8.4"
88-
"@polkadot/jsonrpc" "1.6.2"
89-
"@polkadot/metadata" "1.6.2"
90-
"@polkadot/rpc-provider" "1.6.2"
91-
"@polkadot/types" "1.6.2"
80+
"@babel/runtime" "^7.8.7"
81+
"@polkadot/jsonrpc" "1.7.1"
82+
"@polkadot/metadata" "1.7.1"
83+
"@polkadot/rpc-provider" "1.7.1"
84+
"@polkadot/types" "1.7.1"
9285
"@polkadot/util" "^2.6.2"
9386
memoizee "^0.4.14"
9487
rxjs "^6.5.4"
9588

96-
"@polkadot/rpc-provider@1.6.2":
97-
version "1.6.2"
98-
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-1.6.2.tgz#c8df4dcb4cf6931d691aa02952ac5c9dc68cac6e"
99-
integrity sha512-PJF7124SAOiTLI+ySFkX6BxgPzU8cWrlitvSKHW/ClQHvmF0A8qR2qILiPKwY9rMYbgHbLzJqOyt3JrVPuCVxA==
89+
"@polkadot/rpc-provider@1.7.1":
90+
version "1.7.1"
91+
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-1.7.1.tgz#745bfda406281783a7cb2d350e1ac72f4795d54c"
92+
integrity sha512-AVAoqeXBNEvy9B1n9Gs0ENW/AHRnHqwDMysAz5hCdoQZXuSYh2WTikXbIsvWH1ouS1Fu3x0pfZW1s2EONonYWA==
10093
dependencies:
101-
"@babel/runtime" "^7.8.4"
102-
"@polkadot/jsonrpc" "1.6.2"
103-
"@polkadot/metadata" "1.6.2"
104-
"@polkadot/types" "1.6.2"
94+
"@babel/runtime" "^7.8.7"
95+
"@polkadot/jsonrpc" "1.7.1"
96+
"@polkadot/metadata" "1.7.1"
97+
"@polkadot/types" "1.7.1"
10598
"@polkadot/util" "^2.6.2"
10699
"@polkadot/util-crypto" "^2.6.2"
107100
bn.js "^5.1.1"
108101
eventemitter3 "^4.0.0"
109102
isomorphic-fetch "^2.2.1"
110103
websocket "^1.0.31"
111104

112-
"@polkadot/types@1.6.2":
113-
version "1.6.2"
114-
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-1.6.2.tgz#7a4afce9fcb734c4e5d40dcbce923ee799d84745"
115-
integrity sha512-mo1eKJPcllsaOe+h7kIvjklJXH8c0AqLM9bDGhJtM3O3+aAM99xDItHp02uaoEywCUbc9XqI4+/mH/Lu0fTT3g==
105+
"@polkadot/types@1.7.1":
106+
version "1.7.1"
107+
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-1.7.1.tgz#83a0c6a8ccc621f513d79510280af21632d058b8"
108+
integrity sha512-w0GOVuBssu+AAB5uk5eOiSToTJnej9J7r5M4sdxGb+nJHxnnHcyNYm8j6PtSK0O/UwYgJG4FzUhzSkvRczE+hQ==
116109
dependencies:
117-
"@babel/runtime" "^7.8.4"
118-
"@polkadot/metadata" "1.6.2"
110+
"@babel/runtime" "^7.8.7"
111+
"@polkadot/metadata" "1.7.1"
119112
"@polkadot/util" "^2.6.2"
120113
"@polkadot/util-crypto" "^2.6.2"
121114
"@types/bn.js" "^4.11.6"
@@ -862,11 +855,6 @@ [email protected]:
862855
iconv-lite "0.4.24"
863856
unpipe "1.0.0"
864857

865-
regenerator-runtime@^0.13.2:
866-
version "0.13.3"
867-
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz#7cf6a77d8f5c6f60eb73c5fc1955b2ceb01e6bf5"
868-
integrity sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw==
869-
870858
regenerator-runtime@^0.13.4:
871859
version "0.13.4"
872860
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.4.tgz#e96bf612a3362d12bb69f7e8f74ffeab25c7ac91"

0 commit comments

Comments
 (0)