aptos: fix deploy
This commit is contained in:
parent
8343a987d1
commit
69eb66e16e
|
@ -1,45 +1,52 @@
|
||||||
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
|
||||||
*/
|
*/
|
||||||
export class AptosMessenger {
|
export class AptosMessenger {
|
||||||
client: AptosClient;
|
client: AptosClient;
|
||||||
customOpts = {
|
customOpts = {
|
||||||
gas_unit_price: "100",
|
gas_unit_price: "100",
|
||||||
max_gas_amount: "30000",
|
max_gas_amount: "30000",
|
||||||
|
};
|
||||||
|
coreMessages = "";
|
||||||
|
|
||||||
|
constructor(nodeUrl: string, coreMessages: string) {
|
||||||
|
this.client = new AptosClient(nodeUrl);
|
||||||
|
this.coreMessages = coreMessages;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compiles and publishes the Messenger code
|
||||||
|
*/
|
||||||
|
public async deploy(privateKey: string): Promise<string> {
|
||||||
|
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);
|
||||||
|
|
||||||
|
console.log("Initalizing Aptos Messenger module...");
|
||||||
|
// Initialize the module to register its emitter capability
|
||||||
|
const APTOS_NODE_URL = "http://localhost:8080/";
|
||||||
|
const client = new AptosClient(APTOS_NODE_URL);
|
||||||
|
const sender = new AptosAccount(hexToUint8Array(privateKey));
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
function: `${this.coreMessages}::messenger::init_messenger`,
|
||||||
|
type_arguments: [],
|
||||||
|
arguments: [],
|
||||||
};
|
};
|
||||||
coreMessages = "";
|
const tx = await generateSignAndSubmitEntryFunction(
|
||||||
|
client,
|
||||||
constructor (nodeUrl: string, coreMessages: string) {
|
sender,
|
||||||
this.client = new AptosClient(nodeUrl);
|
payload
|
||||||
this.coreMessages = coreMessages;
|
);
|
||||||
}
|
const res = await client.waitForTransactionWithResult(tx.hash);
|
||||||
|
console.log(JSON.stringify(res, null, 2));
|
||||||
/**
|
return res.hash;
|
||||||
* Compiles and publishes the Messenger code
|
}
|
||||||
*/
|
}
|
||||||
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`
|
|
||||||
const {stdout, stderr} = await exec(cmd);
|
|
||||||
|
|
||||||
console.log("Initalizing Aptos Messenger module...");
|
|
||||||
// Initialize the module to register it's emitter capability
|
|
||||||
const sender = new AptosAccount(Buffer.from(privateKey, 'hex'));
|
|
||||||
|
|
||||||
const txBuilder = new TransactionBuilderRemoteABI(this.client, { sender: sender.address() })
|
|
||||||
const payload = await txBuilder.build(
|
|
||||||
`${this.coreMessages}::messenger::init_messenger`,
|
|
||||||
[],
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
const rawTx = await this.client.generateRawTransaction(sender.address(), payload);
|
|
||||||
console.log("Raw TX Created.");
|
|
||||||
const transactionRes = await this.client.generateSignSubmitTransaction(sender, rawTx);
|
|
||||||
|
|
||||||
return transactionRes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue