Skip to content

Commit

Permalink
add isCompatible to contract
Browse files Browse the repository at this point in the history
  • Loading branch information
voliva committed Nov 15, 2024
1 parent 0668d32 commit 4e187b3
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 364 deletions.
2 changes: 2 additions & 0 deletions examples/ink-playground/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const typedApi = client.getTypedApi(testAzero)
const psp22Sdk = createInkSdk(typedApi, contracts.psp22)
const psp22Contract = psp22Sdk.getContract(ADDRESS.psp22)

console.log("is compatible", await psp22Contract.isCompatible())

// Nested storage query
{
console.log("Query storage of psp22 contract")
Expand Down
2 changes: 1 addition & 1 deletion examples/ink-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@polkadot-api/sdk-ink": "workspace:*",
"@polkadot-labs/hdkd": "^0.0.8",
"@polkadot-labs/hdkd-helpers": "^0.0.8",
"polkadot-api": "^1.7.3",
"polkadot-api": "^1.7.4",
"rxjs": "7.8.1"
}
}
8 changes: 6 additions & 2 deletions packages/common-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@
"prepack": "pnpm run build"
},
"license": "MIT",
"dependencies": {
"polkadot-api": "^1.7.3",
"peerDependencies": {
"polkadot-api": ">=1.7.4",
"rxjs": ">=7.8.1"
},
"devDependencies": {
"polkadot-api": "^1.7.4",
"rxjs": "^7.8.1"
}
}
13 changes: 10 additions & 3 deletions packages/sdk-ink/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@
},
"license": "MIT",
"dependencies": {
"@polkadot-api/common-sdk-utils": "workspace:*",
"@polkadot-api/ink-contracts": "^0.2.0",
"polkadot-api": "^1.7.3",
"@polkadot-api/common-sdk-utils": "workspace:*"
},
"peerDependencies": {
"@polkadot-api/ink-contracts": ">=0.2.1",
"polkadot-api": ">=1.7.4",
"rxjs": ">=7.8.0"
},
"devDependencies": {
"@polkadot-api/ink-contracts": "^0.2.1",
"polkadot-api": "^1.7.4",
"rxjs": "^7.8.1"
}
}
11 changes: 11 additions & 0 deletions packages/sdk-ink/src/get-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ export function getContract<
typedApi.query.Contracts.ContractInfoOf.getValue(address)

return {
async isCompatible() {
try {
const details = await contractDetails
return details
? details.code_hash.asHex() === lookup.metadata.source.hash
: false
} catch (ex) {
console.error(ex)
return false
}
},
getStorage: () => getStorage(typedApi, inkClient, lookup, address),
async query(message, args) {
const msg = inkClient.message(message)
Expand Down
162 changes: 0 additions & 162 deletions packages/sdk-ink/src/get-contracts.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/sdk-ink/src/sdk-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export interface Contract<
T extends InkSdkTypedApi,
D extends GenericInkDescriptors,
> {
isCompatible(): Promise<boolean>
getStorage(): SdkStorage<D["__types"]["storage"]>
query: <L extends string & keyof D["__types"]["messages"]>(
message: L,
Expand Down
Loading

0 comments on commit 4e187b3

Please sign in to comment.