parent
bd57157365
commit
236c053841
@ -14,7 +14,7 @@
|
||||
"@digitalnative/type-definitions": "^1.1.9",
|
||||
"@docknetwork/node-types": "^0.4.6",
|
||||
"@edgeware/node-types": "^3.6.1-wako",
|
||||
"@equilab/definitions": "1.2.5",
|
||||
"@equilab/definitions": "1.2.6",
|
||||
"@interlay/polkabtc-types": "^0.7.4",
|
||||
"@kiltprotocol/type-definitions": "^0.1.8",
|
||||
"@laminar/type-definitions": "^0.3.1",
|
||||
|
||||
@ -6,7 +6,7 @@ import type { AccountData, AccountId, AccountIndex, Address, Balance } from '@po
|
||||
import type { Codec, OverrideBundleDefinition } from '@polkadot/types/types';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
|
||||
import { equilibrium } from '@equilab/definitions';
|
||||
import { equilibrium, equilibriumNext } from '@equilab/definitions';
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { Enum } from '@polkadot/types';
|
||||
@ -37,13 +37,24 @@ type EqBalanceDoubleMap<T> = AugmentedQuery<
|
||||
[AccountId, Currency]
|
||||
>
|
||||
|
||||
export const u64FromCurrency = (currency: string): number => {
|
||||
const buf = Buffer.from(currency.toLowerCase());
|
||||
const size = buf.length;
|
||||
|
||||
return buf.reduce(
|
||||
(val, digit, i) => val + Math.pow(256, size - 1 - i) * digit,
|
||||
0
|
||||
);
|
||||
};
|
||||
|
||||
const transformBalanceStorage = <T>(
|
||||
query: EqBalanceDoubleMap<T>,
|
||||
currency: string,
|
||||
transform: <SB extends Enum>(data: SB) => AccountData,
|
||||
currencyToAsset: (arg: string) => T
|
||||
currencyToAsset: (arg: string, api?: ApiInterfaceRx) => T,
|
||||
api?: ApiInterfaceRx
|
||||
): CommonBalanceMap => {
|
||||
const arg = currencyToAsset(currency);
|
||||
const arg = currencyToAsset(currency, api);
|
||||
|
||||
// HACK as we cannot properly transform queryMulti result, define AccountData getters on standard Enum
|
||||
if (!(Enum as { hacked?: boolean }).hacked) {
|
||||
@ -81,7 +92,7 @@ const signedBalancePredicate = (raw: Codec): raw is SignedBalance =>
|
||||
Object.prototype.hasOwnProperty.call(raw, key)
|
||||
);
|
||||
|
||||
export const createCustomAccount = <A = string>(currency: string, currencyToAsset: (curr: string) => A, accountDataType = 'AccountData'):
|
||||
export const createCustomAccount = <A = string>(currency: string, currencyToAsset: (curr: string, api?: ApiInterfaceRx) => A, accountDataType = 'AccountData'):
|
||||
(instanceId: string, api: ApiInterfaceRx) => RxResult<(arg: string | Uint8Array | AccountId) => Observable<AccountData>> => (instanceId: string, api: ApiInterfaceRx) => {
|
||||
const registry = api.registry;
|
||||
|
||||
@ -106,7 +117,8 @@ export const createCustomAccount = <A = string>(currency: string, currencyToAsse
|
||||
api.query.eqBalances.account as unknown as EqBalanceDoubleMap<A>,
|
||||
currency,
|
||||
transform,
|
||||
currencyToAsset
|
||||
currencyToAsset,
|
||||
api
|
||||
);
|
||||
};
|
||||
|
||||
@ -116,7 +128,17 @@ const definitions: OverrideBundleDefinition = {
|
||||
(all, cur) => ({
|
||||
...all,
|
||||
[cur]: {
|
||||
customAccount: createCustomAccount(cur, (currency: string) => currency)
|
||||
customAccount: createCustomAccount(cur, (currency: string, api?: ApiInterfaceRx) => {
|
||||
let assetsEnabled = true;
|
||||
|
||||
try {
|
||||
api?.registry.createType('AssetIdInnerType' as any);
|
||||
} catch (_) {
|
||||
assetsEnabled = false;
|
||||
}
|
||||
|
||||
return assetsEnabled ? { 0: u64FromCurrency(currency) } : currency;
|
||||
})
|
||||
}
|
||||
}),
|
||||
{}
|
||||
@ -127,9 +149,12 @@ const definitions: OverrideBundleDefinition = {
|
||||
|
||||
types: [
|
||||
{
|
||||
// on all versions
|
||||
minmax: [0, undefined],
|
||||
minmax: [0, 262],
|
||||
types: equilibrium.types
|
||||
},
|
||||
{
|
||||
minmax: [263, undefined],
|
||||
types: equilibriumNext.types
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
@ -5,17 +5,7 @@ import type { OverrideBundleDefinition } from '@polkadot/types/types';
|
||||
|
||||
import { genshiro } from '@equilab/definitions';
|
||||
|
||||
import { createCustomAccount } from './equilibrium';
|
||||
|
||||
export const u64FromCurrency = (currency: string): number => {
|
||||
const buf = Buffer.from(currency.toLowerCase());
|
||||
const size = buf.length;
|
||||
|
||||
return buf.reduce(
|
||||
(val, digit, i) => val + Math.pow(256, size - 1 - i) * digit,
|
||||
0
|
||||
);
|
||||
};
|
||||
import { createCustomAccount, u64FromCurrency } from './equilibrium';
|
||||
|
||||
const definitions: OverrideBundleDefinition = {
|
||||
derives: {
|
||||
|
||||
10
yarn.lock
10
yarn.lock
@ -1604,10 +1604,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@equilab/definitions@npm:1.2.5":
|
||||
version: 1.2.5
|
||||
resolution: "@equilab/definitions@npm:1.2.5"
|
||||
checksum: aa8ce21d12b320bd21235e40d3ab2b64ec4520d00d7b55ccfac2c8bd27354a59c025452a13876b24f2222d5aba1b29e1b4b312bbcee84267b731cb74695340ce
|
||||
"@equilab/definitions@npm:1.2.6":
|
||||
version: 1.2.6
|
||||
resolution: "@equilab/definitions@npm:1.2.6"
|
||||
checksum: e58599e6611bfab6fe8d108f5afd5607cdbb7118351232144fad74874b964f0b595edee3e38f6f91309c53dc2eeb2803e860db4ece386d8a69a1b43389db81c3
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -2554,7 +2554,7 @@ __metadata:
|
||||
"@digitalnative/type-definitions": ^1.1.9
|
||||
"@docknetwork/node-types": ^0.4.6
|
||||
"@edgeware/node-types": ^3.6.1-wako
|
||||
"@equilab/definitions": 1.2.5
|
||||
"@equilab/definitions": 1.2.6
|
||||
"@interlay/polkabtc-types": ^0.7.4
|
||||
"@kiltprotocol/type-definitions": ^0.1.8
|
||||
"@laminar/type-definitions": ^0.3.1
|
||||
|
||||
Loading…
Reference in New Issue
Block a user