Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
daoauth committed Jul 22, 2024
1 parent bf84ed1 commit 5cb0dea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
17 changes: 8 additions & 9 deletions src/component/chains/Sui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { STATE } from '../../recoil';
import { Provenance } from '../Provenance';
import { parseMoveToml } from '../utils/parseMoveToml';

import type { ITomlUpgrade } from '../utils/parseMoveToml';

export const Sui = () => {
const { networks, selectNetwork } = useSuiClientContext();
const { mutateAsync: signTransaction } = useSignTransaction();
Expand All @@ -36,18 +38,15 @@ export const Sui = () => {
dependencies: string[];
digest: number[];
};
const {
package: { authors }, // TEMP
} = parseMoveToml(state.files['Move.toml']);

const transaction = new Transaction();
transaction.setSender(account.address);

if (authors && authors[0] && authors[1]) {
// TEMP: transaction.upgrade
const packageId = authors[0];
const upgradeCap = authors[1];
const cap = transaction.object(upgradeCap);
if (state.files['Upgrade.toml']) {
const {
upgrade: { package_id, upgrade_cap },
} = parseMoveToml<ITomlUpgrade>(state.files['Upgrade.toml']);
const cap = transaction.object(upgrade_cap);
const ticket = transaction.moveCall({
target: '0x2::package::authorize_upgrade',
arguments: [
Expand All @@ -59,7 +58,7 @@ export const Sui = () => {
const receipt = transaction.upgrade({
modules,
dependencies,
package: packageId,
package: package_id,
ticket,
});
transaction.moveCall({
Expand Down
30 changes: 19 additions & 11 deletions src/component/utils/parseMoveToml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,30 @@ export interface IMoveDependency {
rev: string;
}

export const parseMoveToml = (toml: string | Uint8Array) => {
export interface ITomlMove {
package: {
edition: string;
name: string;
version: string;
};
addresses: { [key: string]: string };
dependencies: { [key: string]: IMoveDependency };
}

export interface ITomlUpgrade {
upgrade: {
package_id: string;
upgrade_cap: string;
};
}

export const parseMoveToml = <T>(toml: string | Uint8Array): T => {
try {
return parse(
new TextDecoder().decode(
typeof toml === 'string' ? new TextEncoder().encode(toml) : toml,
),
) as unknown as {
package: {
edition: string;
name: string;
version: string;
authors: string[]; // TEMP
};
addresses: { [key: string]: string };
dependencies: { [key: string]: IMoveDependency };
};
) as T;
} catch (error) {
throw new Error(`${error}`);
}
Expand Down

0 comments on commit 5cb0dea

Please sign in to comment.