Standardize ExecuteResult, InstantiateResult, UploadResult

This commit is contained in:
Simon Warta 2020-03-02 13:24:28 +01:00
parent 7576033134
commit 01758aadb2
8 changed files with 46 additions and 17 deletions

View File

@ -313,7 +313,7 @@ describe("CosmWasmClient", () => {
);
const { codeId } = await client.upload(getRandomizedHackatom());
const initMsg = { verifier: makeRandomAddress(), beneficiary: makeRandomAddress() };
const contractAddress = await client.instantiate(codeId, initMsg, "random hackatom");
const { contractAddress } = await client.instantiate(codeId, initMsg, "random hackatom");
contract = { initMsg: initMsg, address: contractAddress };
}
});
@ -366,7 +366,7 @@ describe("CosmWasmClient", () => {
);
const { codeId } = await client.upload(getRandomizedHackatom());
const initMsg = { verifier: makeRandomAddress(), beneficiary: makeRandomAddress() };
const contractAddress = await client.instantiate(codeId, initMsg, "a different hackatom");
const { contractAddress } = await client.instantiate(codeId, initMsg, "a different hackatom");
contract = { initMsg: initMsg, address: contractAddress };
}
});

View File

@ -29,9 +29,10 @@ export {
export { findSequenceForSignedTx } from "./sequence";
export { encodeSecp256k1Signature, decodeSignature } from "./signature";
export {
ExecuteResult,
InstantiateResult,
SigningCallback,
SigningCosmWasmClient,
ExecuteResult,
UploadMeta,
UploadReceipt,
UploadResult,
} from "./signingcosmwasmclient";

View File

@ -87,7 +87,7 @@ describe("SigningCosmWasmClient", () => {
},
];
const beneficiaryAddress = makeRandomAddress();
const contractAddress = await client.instantiate(
const { contractAddress } = await client.instantiate(
codeId,
{
verifier: faucet.address,
@ -148,7 +148,7 @@ describe("SigningCosmWasmClient", () => {
},
];
const beneficiaryAddress = makeRandomAddress();
const contractAddress = await client.instantiate(
const { contractAddress } = await client.instantiate(
codeId,
{
verifier: faucet.address,

View File

@ -68,7 +68,7 @@ export interface UploadMeta {
readonly builder?: string;
}
export interface UploadReceipt {
export interface UploadResult {
/** Size of the original wasm code in bytes */
readonly originalSize: number;
/** A hex encoded sha256 checksum of the original wasm code (that is stored on chain) */
@ -79,6 +79,17 @@ export interface UploadReceipt {
readonly compressedChecksum: string;
/** The ID of the code asigned by the chain */
readonly codeId: number;
readonly logs: readonly Log[];
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string;
}
export interface InstantiateResult {
/** The address of the newly instantiated contract */
readonly contractAddress: string;
readonly logs: readonly Log[];
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string;
}
export interface ExecuteResult {
@ -115,7 +126,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
}
/** Uploads code and returns a receipt, including the code ID */
public async upload(wasmCode: Uint8Array, meta: UploadMeta = {}, memo = ""): Promise<UploadReceipt> {
public async upload(wasmCode: Uint8Array, meta: UploadMeta = {}, memo = ""): Promise<UploadResult> {
const source = meta.source || "";
const builder = prepareBuilder(meta.builder);
@ -150,6 +161,8 @@ export class SigningCosmWasmClient extends CosmWasmClient {
compressedSize: compressed.length,
compressedChecksum: Encoding.toHex(new Sha256(compressed).digest()),
codeId: Number.parseInt(codeIdAttr.value, 10),
logs: result.logs,
transactionHash: result.transactionHash,
};
}
@ -159,7 +172,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
label: string,
memo = "",
transferAmount?: readonly Coin[],
): Promise<string> {
): Promise<InstantiateResult> {
const instantiateMsg: MsgInstantiateContract = {
type: "wasm/instantiate",
value: {
@ -188,7 +201,11 @@ export class SigningCosmWasmClient extends CosmWasmClient {
const result = await this.postTx(signedTx);
const contractAddressAttr = findAttribute(result.logs, "message", "contract_address");
return contractAddressAttr.value;
return {
contractAddress: contractAddressAttr.value,
logs: result.logs,
transactionHash: result.transactionHash,
};
}
public async execute(

View File

@ -28,9 +28,10 @@ export {
export { findSequenceForSignedTx } from "./sequence";
export { encodeSecp256k1Signature, decodeSignature } from "./signature";
export {
ExecuteResult,
InstantiateResult,
SigningCallback,
SigningCosmWasmClient,
ExecuteResult,
UploadMeta,
UploadReceipt,
UploadResult,
} from "./signingcosmwasmclient";

View File

@ -17,7 +17,7 @@ export interface UploadMeta {
/** The builder tag */
readonly builder?: string;
}
export interface UploadReceipt {
export interface UploadResult {
/** Size of the original wasm code in bytes */
readonly originalSize: number;
/** A hex encoded sha256 checksum of the original wasm code (that is stored on chain) */
@ -28,6 +28,16 @@ export interface UploadReceipt {
readonly compressedChecksum: string;
/** The ID of the code asigned by the chain */
readonly codeId: number;
readonly logs: readonly Log[];
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string;
}
export interface InstantiateResult {
/** The address of the newly instantiated contract */
readonly contractAddress: string;
readonly logs: readonly Log[];
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string;
}
export interface ExecuteResult {
readonly logs: readonly Log[];
@ -48,14 +58,14 @@ export declare class SigningCosmWasmClient extends CosmWasmClient {
getNonce(address?: string): Promise<GetNonceResult>;
getAccount(address?: string): Promise<CosmosSdkAccount | undefined>;
/** Uploads code and returns a receipt, including the code ID */
upload(wasmCode: Uint8Array, meta?: UploadMeta, memo?: string): Promise<UploadReceipt>;
upload(wasmCode: Uint8Array, meta?: UploadMeta, memo?: string): Promise<UploadResult>;
instantiate(
codeId: number,
initMsg: object,
label: string,
memo?: string,
transferAmount?: readonly Coin[],
): Promise<string>;
): Promise<InstantiateResult>;
execute(
contractAddress: string,
handleMsg: object,

View File

@ -82,7 +82,7 @@ async function main() {
for (const initMsg of [initMsgHash, initMsgIsa, initMsgJade]) {
const memo = `Create an ERC20 instance for ${initMsg.symbol}`;
const contractAddress = await client.instantiate(uploadReceipt.codeId, initMsg, initMsg.symbol, memo);
const { contractAddress } = await client.instantiate(uploadReceipt.codeId, initMsg, initMsg.symbol, memo);
console.info(`Contract instantiated for ${initMsg.symbol} at ${contractAddress}`);
}
}

View File

@ -45,7 +45,7 @@ async function main() {
for (const { label, initMsg } of [free, luxury]) {
const memo = `Create an nameservice instance "${label}"`;
const contractAddress = await client.instantiate(uploadReceipt.codeId, initMsg, label, memo);
const { contractAddress } = await client.instantiate(uploadReceipt.codeId, initMsg, label, memo);
console.info(`Contract "${label}" instantiated at ${contractAddress}`);
}
}