-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a72635
commit e25660c
Showing
12 changed files
with
1,112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
squid-ink/src/chains/watrtestnet/normalised-types/calls.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as ss58 from "@subsquid/ss58"; | ||
import { ResolvedContractsCallCall } from "chains/normalised-return-types"; | ||
import { ss58Format } from "../../../chain-config"; | ||
import { ContractsCallCall } from "../types/calls"; | ||
|
||
export class NormalisedContractsCallCall extends ContractsCallCall { | ||
resolve(): ResolvedContractsCallCall { | ||
if (this.isWatrNodeV1000) { | ||
const { dest, value, gasLimit, storageDepositLimit, data } = | ||
this.asWatrNodeV1000; | ||
// TODO: Ensure proper support of MultiAddress | ||
if (dest.__kind === "Index") { | ||
throw new Error("Multi-address of type Index is not supported!"); | ||
} | ||
return { | ||
contractAddress: ss58.codec(ss58Format).encode(dest.value), | ||
value, | ||
gasLimit: { | ||
refTime: gasLimit, | ||
}, | ||
storageDepositLimit, | ||
data, | ||
}; | ||
} | ||
throw new Error("No Runtime version found"); | ||
} | ||
} |
189 changes: 189 additions & 0 deletions
189
squid-ink/src/chains/watrtestnet/normalised-types/events.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
// eslint-disable-next-line eslint-comments/disable-enable-pair | ||
/* eslint-disable max-classes-per-file */ | ||
import * as ss58 from "@subsquid/ss58"; | ||
import { toHex } from "@subsquid/util-internal-hex"; | ||
import { | ||
ResolvedBalancesEndowedEvent, | ||
ResolvedBalancesReservedEvent, | ||
ResolvedBalancesTransferEvent, | ||
ResolvedBalancesWithdrawEvent, | ||
ResolvedContractEmittedEvent, | ||
ResolvedContractCodeRemovedEvent, | ||
ResolvedContractsCodeStoredEvent, | ||
ResolvedContractsCodeUpdatedEvent, | ||
ResolvedContractsInstantiatedEvent, | ||
ResolvedContractTerminatedEvent, | ||
ResolvedNewAccountEvent, | ||
} from "chains/normalised-return-types"; | ||
import { ss58Format } from "../../../chain-config"; | ||
import { | ||
BalancesEndowedEvent, | ||
BalancesReservedEvent, | ||
BalancesTransferEvent, | ||
BalancesWithdrawEvent, | ||
ContractsCodeRemovedEvent, | ||
ContractsCodeStoredEvent, | ||
ContractsContractCodeUpdatedEvent, | ||
ContractsContractEmittedEvent, | ||
ContractsInstantiatedEvent, | ||
ContractsTerminatedEvent, | ||
SystemNewAccountEvent, | ||
} from "../types/events"; | ||
|
||
export class NormalisedBalancesTransferEvent extends BalancesTransferEvent { | ||
resolve(): ResolvedBalancesTransferEvent { | ||
if (this.isWatrNodeV1000) { | ||
const { from, to, amount } = this.asWatrNodeV1000; | ||
return { | ||
from: ss58.codec(ss58Format).encode(from), | ||
to: ss58.codec(ss58Format).encode(to), | ||
amount, | ||
}; | ||
} | ||
throw new Error( | ||
"No runtime version found while decoding [BalancesTransferEvent]" | ||
); | ||
} | ||
} | ||
|
||
export class NormalisedBalancesEndowedEvent extends BalancesEndowedEvent { | ||
resolve(): ResolvedBalancesEndowedEvent { | ||
if (this.isWatrNodeV1000) { | ||
const { account, freeBalance } = this.asWatrNodeV1000; | ||
return { | ||
account: ss58.codec(ss58Format).encode(account), | ||
freeBalance, | ||
}; | ||
} | ||
throw new Error( | ||
"No runtime version found while decoding [BalancesEndowedEvent]" | ||
); | ||
} | ||
} | ||
|
||
export class NormalisedBalancesWithdrawEvent extends BalancesWithdrawEvent { | ||
resolve(): ResolvedBalancesWithdrawEvent { | ||
if (this.isWatrNodeV1000) { | ||
const { who, amount } = this.asWatrNodeV1000; | ||
return { | ||
account: ss58.codec(ss58Format).encode(who), | ||
amount, | ||
}; | ||
} | ||
throw new Error( | ||
"No runtime version found while decoding [BalancesWithdrawEvent]" | ||
); | ||
} | ||
} | ||
|
||
export class NormalisedBalancesReservedEvent extends BalancesReservedEvent { | ||
resolve(): ResolvedBalancesReservedEvent { | ||
if (this.isWatrNodeV1000) { | ||
const { who, amount } = this.asWatrNodeV1000; | ||
return { | ||
account: ss58.codec(ss58Format).encode(who), | ||
amount, | ||
}; | ||
} | ||
throw new Error( | ||
"No runtime version found while decoding [BalancesReservedEvent]" | ||
); | ||
} | ||
} | ||
|
||
export class NormalisedContractsCodeRemovedEvent extends ContractsCodeRemovedEvent { | ||
resolve(): ResolvedContractCodeRemovedEvent { | ||
if (this.isWatrNodeV1000) { | ||
const { codeHash } = this.asWatrNodeV1000; | ||
return { codeHash: toHex(codeHash) }; | ||
} | ||
throw new Error( | ||
"No runtime version found while decoding [ContractsCodeRemovedEvent]" | ||
); | ||
} | ||
} | ||
|
||
export class NormalisedContractsInstantiatedEvent extends ContractsInstantiatedEvent { | ||
resolve(): ResolvedContractsInstantiatedEvent { | ||
if (this.isWatrNodeV1000) { | ||
const { deployer, contract } = this.asWatrNodeV1000; | ||
return { | ||
deployer: ss58.codec(ss58Format).encode(deployer), | ||
contract: ss58.codec(ss58Format).encode(contract), | ||
}; | ||
} | ||
throw new Error( | ||
"No runtime version found while decoding [ContractsInstantiatedEvent]" | ||
); | ||
} | ||
} | ||
|
||
export class NormalisedContractsCodeStoredEvent extends ContractsCodeStoredEvent { | ||
resolve(): ResolvedContractsCodeStoredEvent { | ||
if (this.isWatrNodeV1000) { | ||
const { codeHash } = this.asWatrNodeV1000; | ||
return { codeHash: toHex(codeHash) }; | ||
} | ||
throw new Error( | ||
"No runtime version found while decoding [ContractsCodeStoredEvent]" | ||
); | ||
} | ||
} | ||
|
||
export class NormalisedContractsCodeUpdatedEvent extends ContractsContractCodeUpdatedEvent { | ||
resolve(): ResolvedContractsCodeUpdatedEvent { | ||
if (this.isWatrNodeV1000) { | ||
const { contract, newCodeHash, oldCodeHash } = this.asWatrNodeV1000; | ||
return { | ||
contract: ss58.codec(ss58Format).encode(contract), | ||
newCodeHash: toHex(newCodeHash), | ||
oldCodeHash: toHex(oldCodeHash), | ||
}; | ||
} | ||
throw new Error( | ||
"No runtime version found while decoding [ContractsContractCodeUpdatedEvent]" | ||
); | ||
} | ||
} | ||
|
||
export class NormalisedContractEmittedEvent extends ContractsContractEmittedEvent { | ||
resolve(): ResolvedContractEmittedEvent { | ||
if (this.isWatrNodeV1000) { | ||
const { contract, data } = this.asWatrNodeV1000; | ||
return { contract: ss58.codec(ss58Format).encode(contract), data }; | ||
} | ||
throw new Error( | ||
"No runtime version found while decoding [ContractsContractEmittedEvent]" | ||
); | ||
} | ||
} | ||
|
||
export class NormalisedContractTerminatedEvent extends ContractsTerminatedEvent { | ||
resolve(): ResolvedContractTerminatedEvent { | ||
if (this.isWatrNodeV1000) { | ||
const { contract, beneficiary } = this.asWatrNodeV1000 as { | ||
contract: Uint8Array; | ||
beneficiary: Uint8Array; | ||
}; | ||
return { | ||
contract: ss58.codec(ss58Format).encode(contract), | ||
beneficiary: ss58.codec(ss58Format).encode(beneficiary), | ||
}; | ||
} | ||
throw new Error( | ||
"No runtime version found while decoding [ContractsTerminatedEvent]" | ||
); | ||
} | ||
} | ||
|
||
export class NormalisedSystemNewAccountEvent extends SystemNewAccountEvent { | ||
resolve(): ResolvedNewAccountEvent { | ||
if (this.isWatrNodeV1000) { | ||
const { account } = this.asWatrNodeV1000; | ||
return { account: ss58.codec(ss58Format).encode(account) }; | ||
} | ||
throw new Error( | ||
"No runtime version found while decoding [SystemNewAccountEvent]" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./calls"; | ||
export * from "./events"; | ||
export * from "./storage"; |
90 changes: 90 additions & 0 deletions
90
squid-ink/src/chains/watrtestnet/normalised-types/storage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import assert from "assert"; | ||
import * as ss58 from "@subsquid/ss58"; | ||
import { decodeHex } from "@subsquid/util-internal-hex"; | ||
import { ResolvedContractInfoOfStorage } from "chains/normalised-return-types"; | ||
import { | ||
BalancesAccountStorage, | ||
ContractsCodeStorageStorage, | ||
ContractsContractInfoOfStorage, | ||
ContractsOwnerInfoOfStorage, | ||
SystemAccountStorage, | ||
} from "../types/storage"; | ||
import { | ||
AccountData, | ||
AccountInfo, | ||
OwnerInfo, | ||
PrefabWasmModule, | ||
} from "../types/watrNodeV1000"; | ||
import { ss58Format } from "../../../chain-config"; | ||
|
||
export class NormalisedSystemAccountStorage extends SystemAccountStorage { | ||
async get(accountId: string): Promise<AccountInfo> { | ||
assert(this.isExists); | ||
if (this.isWatrNodeV1000) { | ||
return this.getAsWatrNodeV1000(ss58.codec(ss58Format).decode(accountId)); | ||
} | ||
throw new Error("No Runtime version found"); | ||
} | ||
} | ||
|
||
export class NormalisedBalancesAccountStorage extends BalancesAccountStorage { | ||
async get(accountId: string): Promise<AccountData> { | ||
assert(this.isExists); | ||
if (this.isWatrNodeV1000) { | ||
return this.getAsWatrNodeV1000(ss58.codec(ss58Format).decode(accountId)); | ||
} | ||
throw new Error("No Runtime version found"); | ||
} | ||
} | ||
|
||
export class NormalisedContractInfoOfStorage extends ContractsContractInfoOfStorage { | ||
async get(accountId: string): Promise<ResolvedContractInfoOfStorage> { | ||
assert(this.isExists); | ||
let info: ResolvedContractInfoOfStorage | undefined; | ||
if (this.isWatrNodeV1000) { | ||
info = await this.getAsWatrNodeV1000( | ||
ss58.codec(ss58Format).decode(accountId) | ||
); | ||
} else { | ||
throw new Error("No Runtime version found"); | ||
} | ||
if (info) { | ||
return info; | ||
} | ||
throw new Error( | ||
`ContractInfoOf not found in storage for accountId [${accountId}]` | ||
); | ||
} | ||
} | ||
|
||
export class NormalisedCodeStorageStorage extends ContractsCodeStorageStorage { | ||
async get(key: string): Promise<PrefabWasmModule> { | ||
assert(this.isExists); | ||
let info: PrefabWasmModule | undefined; | ||
if (this.isWatrNodeV1000) { | ||
info = await this.getAsWatrNodeV1000(decodeHex(key)); | ||
} else { | ||
throw new Error("No Runtime version found"); | ||
} | ||
if (info) { | ||
return info; | ||
} | ||
throw new Error(`CodeStorage not found in storage for key [${key}]`); | ||
} | ||
} | ||
|
||
export class NormalisedOwnerInfoOfStorage extends ContractsOwnerInfoOfStorage { | ||
async get(key: string): Promise<OwnerInfo> { | ||
assert(this.isExists); | ||
let info: OwnerInfo | undefined; | ||
if (this.isWatrNodeV1000) { | ||
info = await this.getAsWatrNodeV1000(decodeHex(key)); | ||
} else { | ||
throw new Error("No Runtime version found"); | ||
} | ||
if (info) { | ||
return info; | ||
} | ||
throw new Error(`CodeStorage not found in storage for key [${key}]`); | ||
} | ||
} |
Oops, something went wrong.