Skip to content

Commit 42225b4

Browse files
api, api-{augment, base, contract, derive}, rpc-{augment, core, provider}, types, types-{augment, codec, create, known} 12.4.1
1 parent 1cd4b7b commit 42225b4

File tree

21 files changed

+118
-36
lines changed

21 files changed

+118
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## master
44

5+
- api, api-{augment, base, contract, derive}, rpc-{augment, core, provider}, types, types-{augment, codec, create, known} 12.4.1
56
- phishing 0.23.3
67
- api, api-{augment, base, contract, derive}, rpc-{augment, core, provider}, types, types-{augment, codec, create, known} 12.3.1
78
- phishing 0.23.2

api-augment/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api-augment', path: new URL(import.meta.url).pathname, type: 'deno', version: '12.3.1' };
3+
export const packageInfo = { name: '@polkadot/api-augment', path: new URL(import.meta.url).pathname, type: 'deno', version: '12.4.1' };

api-base/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api-base', path: new URL(import.meta.url).pathname, type: 'deno', version: '12.3.1' };
3+
export const packageInfo = { name: '@polkadot/api-base', path: new URL(import.meta.url).pathname, type: 'deno', version: '12.4.1' };

api-contract/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api-contract', path: new URL(import.meta.url).pathname, type: 'deno', version: '12.3.1' };
3+
export const packageInfo = { name: '@polkadot/api-contract', path: new URL(import.meta.url).pathname, type: 'deno', version: '12.4.1' };

api-derive/balances/account.ts

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import type { Observable } from 'https://esm.sh/rxjs@7.8.1';
33
import type { QueryableStorageEntry } from 'https://deno.land/x/polkadot/api-base/types/index.ts';
44
import type { AccountData, AccountId, AccountIndex, AccountInfo, Address, Balance, Index } from 'https://deno.land/x/polkadot/types/interfaces/index.ts';
5+
import type { FrameSystemAccountInfo, PalletBalancesAccountData } from 'https://deno.land/x/polkadot/types/lookup.ts';
56
import type { ITuple } from 'https://deno.land/x/polkadot/types/types/index.ts';
67
import type { DeriveApi, DeriveBalancesAccount, DeriveBalancesAccountData } from '../types.ts';
78

@@ -13,7 +14,9 @@ import { memo } from '../util/index.ts';
1314

1415
type BalanceResult = [Balance, Balance, Balance, Balance];
1516

16-
type Result = [Index, BalanceResult[]];
17+
type Result = [Index, BalanceResult[], AccountType];
18+
19+
interface AccountType { isFrameAccountData: boolean }
1720

1821
type DeriveCustomAccount = DeriveApi['derive'] & Record<string, {
1922
customAccount?: DeriveApi['query']['balances']['account']
@@ -23,24 +26,38 @@ function zeroBalance (api: DeriveApi) {
2326
return api.registry.createType('Balance');
2427
}
2528

26-
function getBalance (api: DeriveApi, [freeBalance, reservedBalance, frozenFee, frozenMisc]: BalanceResult): DeriveBalancesAccountData {
29+
function getBalance (api: DeriveApi, [freeBalance, reservedBalance, frozenFeeOrFrozen, frozenMiscOrFlags]: BalanceResult, accType: AccountType): DeriveBalancesAccountData {
2730
const votingBalance = api.registry.createType('Balance', freeBalance.toBn());
2831

32+
if (accType.isFrameAccountData) {
33+
return {
34+
frameSystemAccountInfo: {
35+
flags: frozenMiscOrFlags,
36+
frozen: frozenFeeOrFrozen
37+
},
38+
freeBalance,
39+
frozenFee: api.registry.createType('Balance', 0),
40+
frozenMisc: api.registry.createType('Balance', 0),
41+
reservedBalance,
42+
votingBalance
43+
};
44+
}
45+
2946
return {
3047
freeBalance,
31-
frozenFee,
32-
frozenMisc,
48+
frozenFee: frozenFeeOrFrozen,
49+
frozenMisc: frozenMiscOrFlags,
3350
reservedBalance,
3451
votingBalance
3552
};
3653
}
3754

38-
function calcBalances (api: DeriveApi, [accountId, [accountNonce, [primary, ...additional]]]: [AccountId, Result]): DeriveBalancesAccount {
55+
function calcBalances (api: DeriveApi, [accountId, [accountNonce, [primary, ...additional], accType]]: [AccountId, Result]): DeriveBalancesAccount {
3956
return objectSpread({
4057
accountId,
4158
accountNonce,
42-
additional: additional.map((b) => getBalance(api, b))
43-
}, getBalance(api, primary));
59+
additional: additional.map((b) => getBalance(api, b, accType))
60+
}, getBalance(api, primary, accType));
4461
}
4562

4663
function queryBalancesFree (api: DeriveApi, accountId: AccountId): Observable<Result> {
@@ -51,15 +68,17 @@ function queryBalancesFree (api: DeriveApi, accountId: AccountId): Observable<Re
5168
]).pipe(
5269
map(([freeBalance, reservedBalance, accountNonce]): Result => [
5370
accountNonce,
54-
[[freeBalance, reservedBalance, zeroBalance(api), zeroBalance(api)]]
71+
[[freeBalance, reservedBalance, zeroBalance(api), zeroBalance(api)]],
72+
{ isFrameAccountData: false }
5573
])
5674
);
5775
}
5876

5977
function queryNonceOnly (api: DeriveApi, accountId: AccountId): Observable<Result> {
6078
const fill = (nonce: Index): Result => [
6179
nonce,
62-
[[zeroBalance(api), zeroBalance(api), zeroBalance(api), zeroBalance(api)]]
80+
[[zeroBalance(api), zeroBalance(api), zeroBalance(api), zeroBalance(api)]],
81+
{ isFrameAccountData: false }
6382
];
6483

6584
return isFunction(api.query.system.account)
@@ -80,7 +99,8 @@ function queryBalancesAccount (api: DeriveApi, accountId: AccountId, modules: st
8099

81100
const extract = (nonce: Index, data: AccountData[]): Result => [
82101
nonce,
83-
data.map(({ feeFrozen, free, miscFrozen, reserved }): BalanceResult => [free, reserved, feeFrozen, miscFrozen])
102+
data.map(({ feeFrozen, free, miscFrozen, reserved }): BalanceResult => [free, reserved, feeFrozen, miscFrozen]),
103+
{ isFrameAccountData: false }
84104
];
85105

86106
// NOTE this is for the first case where we do have instances specified
@@ -103,7 +123,7 @@ function queryBalancesAccount (api: DeriveApi, accountId: AccountId, modules: st
103123

104124
function querySystemAccount (api: DeriveApi, accountId: AccountId): Observable<Result> {
105125
// AccountInfo is current, support old, eg. Edgeware
106-
return api.query.system.account<AccountInfo | ITuple<[Index, AccountData]>>(accountId).pipe(
126+
return api.query.system.account<AccountInfo | FrameSystemAccountInfo | ITuple<[Index, AccountData]>>(accountId).pipe(
107127
map((infoOrTuple): Result => {
108128
const data = (infoOrTuple as AccountInfo).nonce
109129
? (infoOrTuple as AccountInfo).data
@@ -114,16 +134,30 @@ function querySystemAccount (api: DeriveApi, accountId: AccountId): Observable<R
114134
if (!data || data.isEmpty) {
115135
return [
116136
nonce,
117-
[[zeroBalance(api), zeroBalance(api), zeroBalance(api), zeroBalance(api)]]
137+
[[zeroBalance(api), zeroBalance(api), zeroBalance(api), zeroBalance(api)]],
138+
{ isFrameAccountData: false }
118139
];
119140
}
120141

121-
const { feeFrozen, free, miscFrozen, reserved } = data;
142+
const isFrameType = !!(infoOrTuple as FrameSystemAccountInfo).data.frozen;
143+
144+
if (isFrameType) {
145+
const { flags, free, frozen, reserved } = (data as unknown as PalletBalancesAccountData);
122146

123-
return [
124-
nonce,
125-
[[free, reserved, feeFrozen, miscFrozen]]
126-
];
147+
return [
148+
nonce,
149+
[[free, reserved, frozen, flags]],
150+
{ isFrameAccountData: true }
151+
];
152+
} else {
153+
const { feeFrozen, free, miscFrozen, reserved } = data;
154+
155+
return [
156+
nonce,
157+
[[free, reserved, feeFrozen, miscFrozen]],
158+
{ isFrameAccountData: false }
159+
];
160+
}
127161
})
128162
);
129163
}
@@ -165,7 +199,8 @@ export function account (instanceId: string, api: DeriveApi): (address: AccountI
165199
])
166200
: of([api.registry.createType('AccountId'), [
167201
api.registry.createType('Index'),
168-
[[zeroBalance(api), zeroBalance(api), zeroBalance(api), zeroBalance(api)]]
202+
[[zeroBalance(api), zeroBalance(api), zeroBalance(api), zeroBalance(api)]],
203+
{ isFrameAccountData: false }
169204
]])
170205
)
171206
),

api-derive/balances/all.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,28 @@ function calcLocked (api: DeriveApi, bestNumber: BlockNumber, locks: (PalletBala
5252

5353
function calcShared (api: DeriveApi, bestNumber: BlockNumber, data: DeriveBalancesAccountData, locks: (PalletBalancesBalanceLock | BalanceLockTo212)[]): DeriveBalancesAllAccountData {
5454
const { allLocked, lockedBalance, lockedBreakdown, vestingLocked } = calcLocked(api, bestNumber, locks);
55+
let transferable = null;
56+
57+
if (data.frameSystemAccountInfo?.frozen) {
58+
const { frameSystemAccountInfo, freeBalance, reservedBalance } = data;
59+
const noFrozenReserved = frameSystemAccountInfo.frozen.isZero() && reservedBalance.isZero();
60+
const ED = api.consts.balances.existentialDeposit;
61+
const maybeED = noFrozenReserved ? new BN(0) : ED;
62+
const frozenReserveDif = frameSystemAccountInfo.frozen.sub(reservedBalance);
63+
64+
transferable = api.registry.createType(
65+
'Balance',
66+
allLocked
67+
? 0
68+
: freeBalance.sub(bnMax(maybeED, frozenReserveDif))
69+
);
70+
}
5571

5672
return objectSpread({}, data, {
5773
availableBalance: api.registry.createType('Balance', allLocked ? 0 : bnMax(new BN(0), data?.freeBalance ? data.freeBalance.sub(lockedBalance) : new BN(0))),
5874
lockedBalance,
5975
lockedBreakdown,
76+
transferable,
6077
vestingLocked
6178
});
6279
}

api-derive/balances/types.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import type { PalletBalancesBalanceLock, PalletBalancesReserveData } from 'https
44
import type { BN } from 'https://deno.land/x/polkadot/util/mod.ts';
55

66
export interface DeriveBalancesAccountData {
7+
frameSystemAccountInfo?: {
8+
frozen: Balance;
9+
flags: Balance;
10+
}
711
freeBalance: Balance;
812
frozenFee: Balance;
913
frozenMisc: Balance;
@@ -18,9 +22,34 @@ export interface DeriveBalancesAccount extends DeriveBalancesAccountData {
1822
}
1923

2024
export interface DeriveBalancesAllAccountData extends DeriveBalancesAccountData {
25+
/**
26+
* Calculated available balance. This uses the formula: max(0, free - locked)
27+
* This is only correct when the return type of `api.query.system.account` is `AccountInfo` which was replaced by `FrameSystemAccountInfo`.
28+
* See `transferable` for the correct balance calculation.
29+
*
30+
* ref: https://github.com/paritytech/substrate/pull/12951
31+
*/
2132
availableBalance: Balance;
33+
/**
34+
* The amount of balance locked away.
35+
*/
2236
lockedBalance: Balance;
37+
/**
38+
* The breakdown of locked balances.
39+
*/
2340
lockedBreakdown: (PalletBalancesBalanceLock | BalanceLockTo212)[];
41+
/**
42+
* Calculated transferable balance. This uses the formula: free - max(maybeEd, frozen - reserve)
43+
* Where `maybeEd` means if there is no frozen and reserves it will be zero, else it will be the existential deposit.
44+
* This is only correct when the return type of `api.query.system.account` is `FrameSystemAccountInfo`.
45+
* Which is the most up to date calulcation for transferrable balances.
46+
*
47+
* ref: https://github.com/paritytech/polkadot-sdk/issues/1833
48+
*/
49+
transferable: Balance | null;
50+
/**
51+
* Amount locked in vesting.
52+
*/
2453
vestingLocked: Balance;
2554
}
2655

api-derive/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api-derive', path: new URL(import.meta.url).pathname, type: 'deno', version: '12.3.1' };
3+
export const packageInfo = { name: '@polkadot/api-derive', path: new URL(import.meta.url).pathname, type: 'deno', version: '12.4.1' };

api/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api', path: new URL(import.meta.url).pathname, type: 'deno', version: '12.3.1' };
3+
export const packageInfo = { name: '@polkadot/api', path: new URL(import.meta.url).pathname, type: 'deno', version: '12.4.1' };

api/submittable/createClass.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, blockHas
357357
nonce: ext.nonce.toHex(),
358358
runtimeVersion: payload.runtimeVersion,
359359
signedExtensions: payload.signedExtensions,
360-
tip: ext.tip.toHex(),
360+
tip: ext.tip ? ext.tip.toHex() : null,
361361
version: payload.version
362362
})]);
363363

0 commit comments

Comments
 (0)