Skip to content

Commit

Permalink
Merge pull request #76 from logion-network/hotfix/sync2
Browse files Browse the repository at this point in the history
feat: properly use Polkadot custom types.
  • Loading branch information
gdethier authored Jan 31, 2022
2 parents 0908f84 + 0af03af commit 01aad76
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 78 deletions.
82 changes: 5 additions & 77 deletions src/logion/services/polkadot.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { injectable } from 'inversify';
import '../lib/polkadot/interfaces/augment-api';
import '../lib/polkadot/interfaces/augment-types';
import { ApiPromise, WsProvider } from '@polkadot/api';
import * as definitions from '../lib/polkadot/interfaces/definitions';
import { Log } from "../util/Log";

const { logger } = Log;
Expand All @@ -20,85 +23,10 @@ export class PolkadotService {
const wsProviderUrl = process.env.WS_PROVIDER_URL || 'ws://localhost:9944';
logger.info("Connecting to node %s", wsProviderUrl);
const wsProvider = new WsProvider(wsProviderUrl);
const types = Object.values(definitions).reduce((res, { types }): object => ({ ...res, ...types }), {});
return await ApiPromise.create({
provider: wsProvider,
types: {
Address: "MultiAddress",
LookupSource: "MultiAddress",
PeerId: "(Vec<u8>)",
AccountInfo: "AccountInfoWithDualRefCount",
TAssetBalance: "u128",
AssetId: "u64",
AssetDetails: {
owner: "AccountId",
issuer: "AccountId",
admin: "AccountId",
freezer: "AccountId",
supply: "Balance",
deposit: "DepositBalance",
max_zombies: "u32",
min_balance: "Balance",
zombies: "u32",
accounts: "u32",
is_frozen: "bool"
},
AssetMetadata: {
deposit: "DepositBalance",
name: "Vec<u8>",
symbol: "Vec<u8>",
decimals: "u8"
},
LocId: "u128",
LegalOfficerCaseOf: {
owner: "AccountId",
requester: "Requester",
metadata: "Vec<MetadataItem>",
files: "Vec<File>",
closed: "bool",
loc_type: "LocType",
links: "Vec<LocLink>",
void_info: "Option<LocVoidInfo<LocId>>",
replacer_of: "Option<LocId>"
},
MetadataItem: {
name: "Vec<u8>",
value: "Vec<u8>",
submitter: "AccountId",
},
LocType: {
_enum: [
"Transaction",
"Identity"
]
},
LocLink: {
id: "LocId",
nature: "Vec<u8>",
},
File: {
hash: "Hash",
nature: "Vec<u8>",
submitter: "AccountId",
},
LocVoidInfo: {
"replacer": "Option<LocId>"
},
StorageVersion: {
"_enum": [
"V1",
"V2MakeLocVoid",
"V3RequesterEnum",
"V4ItemSubmitter",
]
},
Requester: {
"_enum": {
"None": null,
"Account": "AccountId",
"Loc": "LocId"
}
}
}
types
});
}
}
7 changes: 6 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"outDir": "dist"
"outDir": "dist",
"baseUrl": ".",
"paths": {
"@polkadot/api/augment": ["src/logion/lib/polkadot/interfaces/augment-api.ts"],
"@polkadot/types/augment": ["src/logion/lib/polkadot/interfaces/augment-types.ts"]
}
},
"compileOnSave": false,
"exclude": [
Expand Down

0 comments on commit 01aad76

Please sign in to comment.