Skip to content

Commit 2a26924

Browse files
committed
wip: add contract and calling contracts works. Modifies @polkadot/api-contract
1 parent 8e7f600 commit 2a26924

File tree

7 files changed

+2763
-3319
lines changed

7 files changed

+2763
-3319
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
"@headlessui/react": "^1.7.18",
3535
"@heroicons/react": "^1.0.6",
3636
"@polkadot/api": "15.8.1",
37-
"@polkadot/api-contract": "15.8.1",
37+
"@polkadot/api-contract": "file:/Users/peter/dev/dot-repos/api/packages/api-contract/build",
3838
"@polkadot/extension-dapp": "^0.58.6",
39+
"@polkadot/types": "file:/Users/peter/dev/dot-repos/api/packages/types/build",
3940
"@polkadot/ui-keyring": "^3.12.2",
4041
"@polkadot/ui-shared": "^3.12.2",
4142
"big.js": "^6.2.1",
@@ -44,6 +45,7 @@
4445
"date-fns": "^2.30.0",
4546
"dexie": "^3.2.4",
4647
"dexie-react-hooks": "1.1.7",
48+
"ethers": "^6.13.5",
4749
"json5": "^2.2.3",
4850
"react": "^18.3.1",
4951
"react-dom": "^18.3.1",

src/lib/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export function isUndefined(value: unknown): value is undefined {
7474

7575
export function isValidAddress(address: string | Uint8Array | null | undefined) {
7676
try {
77-
encodeAddress(isHex(address) ? hexToU8a(address) : decodeAddress(address));
77+
// encodeAddress(isHex(address) ? hexToU8a(address) : decodeAddress(address));
7878
return true;
7979
} catch (error) {
8080
return false;

src/services/chain/contract.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ export function createInstantiateTx(
6666
}
6767

6868
export async function getContractInfo(api: ApiPromise, address: string) {
69-
if (isValidAddress(address)) {
70-
return (await api.query.contracts.contractInfoOf(address)).unwrapOr(null);
69+
if (isValidAddress(address) || true) {
70+
return (await api.query.revive.contractInfoOf(address.substring(0, 42))).unwrapOr(null);
7171
}
7272
}
7373

src/ui/components/contract/Interact.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ export const InteractTab = ({
7373
setCallResults([]);
7474
}, [abi.messages, setArgValues, address]);
7575

76-
const params: Parameters<typeof api.call.contractsApi.call> = useMemo(() => {
76+
const params: Parameters<typeof api.call.reviveApi.call> = useMemo(() => {
7777
return [
7878
accountId,
79-
address,
79+
address.substring(0, 42),
8080
message?.isPayable
8181
? api.registry.createType('Balance', value)
8282
: api.registry.createType('Balance', BN_ZERO),
@@ -101,7 +101,7 @@ export const InteractTab = ({
101101
useEffect((): void => {
102102
async function dryRun() {
103103
if (!message) return;
104-
const newOutcome = await api.call.contractsApi.call(...params);
104+
const newOutcome = await api.call.reviveApi.call(...params);
105105

106106
// auto-generated @polkadot/type-augment data uses a different flag representation: `{"ok":{"flags":{"bits":0},"data":"0x00"}}`
107107
let convertedFlags = api.registry.createType('ContractReturnFlags', 0);
@@ -117,7 +117,7 @@ export const InteractTab = ({
117117
gasRequired: newOutcome.gasRequired,
118118
storageDeposit: newOutcome.storageDeposit,
119119
// debugMessage is Bytes, must convert to Text
120-
debugMessage: new Text(api.registry, newOutcome.debugMessage.toUtf8()),
120+
// debugMessage: new Text(api.registry, newOutcome.debugMessage.toUtf8()),
121121
result: newOutcome.result.isOk
122122
? { Ok: { flags: convertedFlags, data: newOutcome.result.asOk.data } }
123123
: { Err: newOutcome.result.asErr },
@@ -136,7 +136,7 @@ export const InteractTab = ({
136136
}
137137

138138
debouncedDryRun();
139-
}, [api.call.contractsApi, message, params, nextResultId]);
139+
}, [api.call.reviveApi, message, params, nextResultId]);
140140

141141
useEffect(() => {
142142
async function processTx() {
@@ -185,10 +185,17 @@ export const InteractTab = ({
185185

186186
const isValid = (result: SubmittableResult) => !result.isError && !result.dispatchError;
187187

188+
console.log('message');
189+
console.log(message);
190+
console.log('tx');
191+
console.log(tx);
192+
console.log(message.method);
193+
console.log(transformUserInput(registry, message.args, argValues));
188194
const extrinsic = tx[message.method](
189195
options,
190196
...transformUserInput(registry, message.args, argValues),
191197
);
198+
console.log(extrinsic);
192199

193200
newId.current = queue({
194201
extrinsic,

src/ui/hooks/useStoredContract.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function useStoredContract(address: string): UIContract | undefined {
3737
displayName: document.name,
3838
tx: contract.tx,
3939
codeHash: document.codeHash,
40-
address: contract.address.toString(),
40+
address: contract.address.toString() + 'e'.repeat(24),
4141
date: document.date,
4242
id: document.id,
4343
type: document.external ? 'added' : 'instantiated',

src/ui/pages/AddressLookup.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,14 @@ export function AddressLookup() {
5959
async function validate() {
6060
if (address !== searchString) {
6161
if (isValidAddress(searchString)) {
62+
console.log(db);
63+
console.log(await db.contracts.count());
64+
// const isOnChain = true;// await getContractInfo(api, searchString);
6265
const isOnChain = await getContractInfo(api, searchString);
63-
if (isOnChain) {
64-
const contract = await db.contracts.get({ address: searchString });
66+
if (true) {
67+
// const contract = await db.contracts.get({ address: searchString });
68+
const contract = undefined;
69+
6570
// Contract is already instantiated in current UI
6671
if (contract) {
6772
navigate(`/contract/${searchString}`);

0 commit comments

Comments
 (0)