aptos: fix deploy

This commit is contained in:
aki 2022-12-14 22:44:48 +00:00
parent 8343a987d1
commit 69eb66e16e
1 changed files with 45 additions and 38 deletions

View File

@ -1,6 +1,10 @@
import { AptosAccount, AptosClient, TransactionBuilder, TransactionBuilderRemoteABI, TxnBuilderTypes, Types } from "aptos"; import {
generateSignAndSubmitEntryFunction,
hexToUint8Array,
} from "@certusone/wormhole-sdk";
import { AptosAccount, AptosClient } from "aptos";
import { promisify } from "util"; import { promisify } from "util";
const exec = promisify(require('child_process').exec); const exec = promisify(require("child_process").exec);
/** /**
* Creates and returns transactions to be submitted by clients * Creates and returns transactions to be submitted by clients
@ -13,7 +17,7 @@ export class AptosMessenger {
}; };
coreMessages = ""; coreMessages = "";
constructor (nodeUrl: string, coreMessages: string) { constructor(nodeUrl: string, coreMessages: string) {
this.client = new AptosClient(nodeUrl); this.client = new AptosClient(nodeUrl);
this.coreMessages = coreMessages; this.coreMessages = coreMessages;
} }
@ -22,24 +26,27 @@ export class AptosMessenger {
* Compiles and publishes the Messenger code * Compiles and publishes the Messenger code
*/ */
public async deploy(privateKey: string): Promise<string> { public async deploy(privateKey: string): Promise<string> {
let cmd = `cd chains/aptos && aptos move compile && aptos move publish --private-key ${privateKey} --url ${this.client.nodeUrl} --assume-yes` let cmd = `cd chains/aptos && aptos move compile --save-metadata && aptos move publish --private-key ${privateKey} --url ${this.client.nodeUrl} --assume-yes`;
const {stdout, stderr} = await exec(cmd); const { stdout, stderr } = await exec(cmd);
console.log("Initalizing Aptos Messenger module..."); console.log("Initalizing Aptos Messenger module...");
// Initialize the module to register it's emitter capability // Initialize the module to register its emitter capability
const sender = new AptosAccount(Buffer.from(privateKey, 'hex')); const APTOS_NODE_URL = "http://localhost:8080/";
const client = new AptosClient(APTOS_NODE_URL);
const sender = new AptosAccount(hexToUint8Array(privateKey));
const txBuilder = new TransactionBuilderRemoteABI(this.client, { sender: sender.address() }) const payload = {
const payload = await txBuilder.build( function: `${this.coreMessages}::messenger::init_messenger`,
`${this.coreMessages}::messenger::init_messenger`, type_arguments: [],
[], arguments: [],
[] };
const tx = await generateSignAndSubmitEntryFunction(
client,
sender,
payload
); );
const res = await client.waitForTransactionWithResult(tx.hash);
const rawTx = await this.client.generateRawTransaction(sender.address(), payload); console.log(JSON.stringify(res, null, 2));
console.log("Raw TX Created."); return res.hash;
const transactionRes = await this.client.generateSignSubmitTransaction(sender, rawTx);
return transactionRes;
} }
} }