mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
commit
19e47d3e2f
@ -11,7 +11,7 @@ const msg: MsgDelegate = {
|
||||
delegator_address: senderAddress,
|
||||
// To get the proper validator address, start the demo chain (./scripts/wasmd/start.sh), then run:
|
||||
// curl http://localhost:1317/staking/validators | jq '.result[0].operator_address'
|
||||
validator_address: "cosmosvaloper1gjvanqxc774u6ed9thj4gpn9gj5zus5u32enqn",
|
||||
validator_address: "cosmosvaloper1fa7hj49pf8uzc4m0lw5swjhhl5th2484gvnlpv",
|
||||
amount: coin(300000, "ustake"),
|
||||
},
|
||||
};
|
||||
|
@ -42,8 +42,8 @@
|
||||
"@cosmjs/cosmwasm": "^0.21.1",
|
||||
"@cosmjs/crypto": "^0.21.1",
|
||||
"@cosmjs/encoding": "^0.21.1",
|
||||
"@cosmjs/launchpad": "^0.21.1",
|
||||
"@cosmjs/math": "^0.21.1",
|
||||
"@cosmjs/sdk38": "^0.21.1",
|
||||
"@cosmjs/utils": "^0.21.1",
|
||||
"axios": "^0.19.2",
|
||||
"babylon": "^6.18.0",
|
||||
|
@ -39,7 +39,7 @@ export function main(originalArgs: readonly string[]): void {
|
||||
"Code",
|
||||
"CodeDetails",
|
||||
"Contract",
|
||||
"ContractDetails",
|
||||
"ContractCodeHistoryEntry",
|
||||
"CosmWasmClient",
|
||||
"GetSequenceResult",
|
||||
"SearchByHeightQuery",
|
||||
@ -78,9 +78,8 @@ export function main(originalArgs: readonly string[]): void {
|
||||
"@cosmjs/encoding",
|
||||
["fromAscii", "fromBase64", "fromHex", "fromUtf8", "toAscii", "toBase64", "toHex", "toUtf8", "Bech32"],
|
||||
],
|
||||
["@cosmjs/math", ["Decimal", "Int53", "Uint32", "Uint53", "Uint64"]],
|
||||
[
|
||||
"@cosmjs/sdk38",
|
||||
"@cosmjs/launchpad",
|
||||
[
|
||||
"coin",
|
||||
"coins",
|
||||
@ -106,6 +105,7 @@ export function main(originalArgs: readonly string[]): void {
|
||||
"StdTx",
|
||||
],
|
||||
],
|
||||
["@cosmjs/math", ["Decimal", "Int53", "Uint32", "Uint53", "Uint64"]],
|
||||
["@cosmjs/utils", ["assert", "sleep"]],
|
||||
]);
|
||||
|
||||
|
@ -8,9 +8,20 @@ An SDK to build CosmWasm clients.
|
||||
|
||||
| CosmWasm | x/wasm | @cosmjs/cosmwasm |
|
||||
| -------- | ------ | ---------------- |
|
||||
| 0.10 | 0.10 | `^0.22.0` |
|
||||
| 0.9 | 0.9 | `^0.21.0` |
|
||||
| 0.8 | 0.8 | `^0.20.1` |
|
||||
|
||||
## Development
|
||||
|
||||
Updating Hackatom development contract in `src/testdata/contract.json`:
|
||||
|
||||
```sh
|
||||
cd packages/cosmwasm
|
||||
export HACKATOM_URL=https://github.com/CosmWasm/cosmwasm/releases/download/v0.10.0-alpha2/hackatom.wasm
|
||||
echo "{\"// source\": \"$HACKATOM_URL\", \"data\": \"$(curl -sS --location $HACKATOM_URL | base64)\" }" | jq > src/testdata/contract.json
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
This package is part of the cosmjs repository, licensed under the Apache License
|
||||
|
@ -40,8 +40,8 @@
|
||||
"dependencies": {
|
||||
"@cosmjs/crypto": "^0.21.1",
|
||||
"@cosmjs/encoding": "^0.21.1",
|
||||
"@cosmjs/launchpad": "^0.21.1",
|
||||
"@cosmjs/math": "^0.21.1",
|
||||
"@cosmjs/sdk38": "^0.21.1",
|
||||
"@cosmjs/utils": "^0.21.1",
|
||||
"axios": "^0.19.0",
|
||||
"fast-deep-equal": "^3.1.1",
|
||||
|
@ -9,7 +9,7 @@ import {
|
||||
makeSignBytes,
|
||||
MsgSend,
|
||||
Secp256k1Wallet,
|
||||
} from "@cosmjs/sdk38";
|
||||
} from "@cosmjs/launchpad";
|
||||
import { assert, sleep } from "@cosmjs/utils";
|
||||
|
||||
import { CosmWasmClient } from "./cosmwasmclient";
|
||||
@ -423,7 +423,7 @@ describe("CosmWasmClient.searchTx", () => {
|
||||
const first = fromOneElementArray(results[0].tx.value.msg);
|
||||
assert(isMsgInstantiateContract(first), "First contract search result must be an instantiation");
|
||||
expect(first).toEqual({
|
||||
type: "wasm/instantiate",
|
||||
type: "wasm/MsgInstantiateContract",
|
||||
value: {
|
||||
sender: alice.address0,
|
||||
code_id: deployedErc20.codeId.toString(),
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { Sha256 } from "@cosmjs/crypto";
|
||||
import { Bech32, fromHex, fromUtf8, toAscii, toBase64 } from "@cosmjs/encoding";
|
||||
import { assertIsPostTxSuccess, makeSignBytes, MsgSend, Secp256k1Wallet, StdFee } from "@cosmjs/sdk38";
|
||||
import { assertIsPostTxSuccess, makeSignBytes, MsgSend, Secp256k1Wallet, StdFee } from "@cosmjs/launchpad";
|
||||
import { assert, sleep } from "@cosmjs/utils";
|
||||
import { ReadonlyDate } from "readonly-date";
|
||||
|
||||
@ -23,10 +23,6 @@ import {
|
||||
|
||||
const blockTime = 1_000; // ms
|
||||
|
||||
const guest = {
|
||||
address: "cosmos17d0jcz59jf68g52vq38tuuncmwwjk42u6mcxej",
|
||||
};
|
||||
|
||||
interface HackatomInstance {
|
||||
readonly initMsg: {
|
||||
readonly verifier: string;
|
||||
@ -344,25 +340,6 @@ describe("CosmWasmClient", () => {
|
||||
creator: alice.address0,
|
||||
label: "HASH",
|
||||
admin: undefined,
|
||||
initMsg: {
|
||||
decimals: 5,
|
||||
name: "Hash token",
|
||||
symbol: "HASH",
|
||||
initial_balances: jasmine.arrayContaining([
|
||||
{
|
||||
address: alice.address0,
|
||||
amount: "11",
|
||||
},
|
||||
{
|
||||
address: unused.address,
|
||||
amount: "12812345",
|
||||
},
|
||||
{
|
||||
address: guest.address,
|
||||
amount: "22004000000",
|
||||
},
|
||||
]),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { Sha256 } from "@cosmjs/crypto";
|
||||
import { fromBase64, fromHex, toHex } from "@cosmjs/encoding";
|
||||
import { Uint53 } from "@cosmjs/math";
|
||||
import {
|
||||
AuthExtension,
|
||||
BroadcastMode,
|
||||
@ -14,7 +13,8 @@ import {
|
||||
setupAuthExtension,
|
||||
StdTx,
|
||||
uint64ToNumber,
|
||||
} from "@cosmjs/sdk38";
|
||||
} from "@cosmjs/launchpad";
|
||||
import { Uint53 } from "@cosmjs/math";
|
||||
|
||||
import { setupWasmExtension, WasmExtension } from "./lcdapi/wasm";
|
||||
import { parseLogs } from "./logs";
|
||||
@ -117,9 +117,10 @@ export interface Contract {
|
||||
readonly label: string;
|
||||
}
|
||||
|
||||
export interface ContractDetails extends Contract {
|
||||
/** Argument passed on initialization of the contract */
|
||||
readonly initMsg: object;
|
||||
export interface ContractCodeHistoryEntry {
|
||||
readonly operation: string;
|
||||
readonly codeId: number;
|
||||
readonly msg: object;
|
||||
}
|
||||
|
||||
export interface BlockHeader {
|
||||
@ -389,7 +390,7 @@ export class CosmWasmClient {
|
||||
/**
|
||||
* Throws an error if no contract was found at the address
|
||||
*/
|
||||
public async getContract(address: string): Promise<ContractDetails> {
|
||||
public async getContract(address: string): Promise<Contract> {
|
||||
const result = await this.lcdClient.wasm.getContractInfo(address);
|
||||
if (!result) throw new Error(`No contract found at address "${address}"`);
|
||||
return {
|
||||
@ -398,10 +399,24 @@ export class CosmWasmClient {
|
||||
creator: result.creator,
|
||||
admin: result.admin,
|
||||
label: result.label,
|
||||
initMsg: result.init_msg,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an error if no contract was found at the address
|
||||
*/
|
||||
public async getContractCodeHistory(address: string): Promise<readonly ContractCodeHistoryEntry[]> {
|
||||
const result = await this.lcdClient.wasm.getContractCodeHistory(address);
|
||||
if (!result) throw new Error(`No contract history found for address "${address}"`);
|
||||
return result.map(
|
||||
(entry): ContractCodeHistoryEntry => ({
|
||||
operation: entry.operation,
|
||||
codeId: entry.code_id,
|
||||
msg: entry.msg,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data at the key if present (raw contract dependent storage data)
|
||||
* or null if no data at this key.
|
||||
|
@ -9,7 +9,7 @@ export {
|
||||
Code,
|
||||
CodeDetails,
|
||||
Contract,
|
||||
ContractDetails,
|
||||
ContractCodeHistoryEntry,
|
||||
CosmWasmClient,
|
||||
GetSequenceResult,
|
||||
SearchByHeightQuery,
|
||||
|
@ -13,7 +13,7 @@ import {
|
||||
Secp256k1Wallet,
|
||||
setupAuthExtension,
|
||||
StdFee,
|
||||
} from "@cosmjs/sdk38";
|
||||
} from "@cosmjs/launchpad";
|
||||
import { assert } from "@cosmjs/utils";
|
||||
|
||||
import { findAttribute, parseLogs } from "../logs";
|
||||
@ -52,7 +52,7 @@ async function uploadContract(
|
||||
): Promise<PostTxsResponse> {
|
||||
const memo = "My first contract on chain";
|
||||
const theMsg: MsgStoreCode = {
|
||||
type: "wasm/store-code",
|
||||
type: "wasm/MsgStoreCode",
|
||||
value: {
|
||||
sender: alice.address0,
|
||||
wasm_byte_code: toBase64(contract.data),
|
||||
@ -86,7 +86,7 @@ async function instantiateContract(
|
||||
): Promise<PostTxsResponse> {
|
||||
const memo = "Create an escrow instance";
|
||||
const theMsg: MsgInstantiateContract = {
|
||||
type: "wasm/instantiate",
|
||||
type: "wasm/MsgInstantiateContract",
|
||||
value: {
|
||||
sender: alice.address0,
|
||||
code_id: codeId.toString(),
|
||||
@ -123,7 +123,7 @@ async function executeContract(
|
||||
): Promise<PostTxsResponse> {
|
||||
const memo = "Time for action";
|
||||
const theMsg: MsgExecuteContract = {
|
||||
type: "wasm/execute",
|
||||
type: "wasm/MsgExecuteContract",
|
||||
value: {
|
||||
sender: alice.address0,
|
||||
contract: contractAddress,
|
||||
@ -268,7 +268,7 @@ describe("wasm", () => {
|
||||
{
|
||||
// console.log("Raw log:", result.raw_log);
|
||||
const result = await uploadContract(client, wallet, getHackatom());
|
||||
expect(result.code).toBeFalsy();
|
||||
assert(!result.code);
|
||||
const logs = parseLogs(result.logs);
|
||||
const codeIdAttr = findAttribute(logs, "message", "code_id");
|
||||
codeId = Number.parseInt(codeIdAttr.value, 10);
|
||||
@ -282,7 +282,7 @@ describe("wasm", () => {
|
||||
// instantiate
|
||||
{
|
||||
const result = await instantiateContract(client, wallet, codeId, beneficiaryAddress, transferAmount);
|
||||
expect(result.code).toBeFalsy();
|
||||
assert(!result.code);
|
||||
// console.log("Raw log:", result.raw_log);
|
||||
const logs = parseLogs(result.logs);
|
||||
const contractAddressAttr = findAttribute(logs, "message", "contract_address");
|
||||
@ -298,8 +298,8 @@ describe("wasm", () => {
|
||||
// execute
|
||||
{
|
||||
const result = await executeContract(client, wallet, contractAddress, { release: {} });
|
||||
assert(!result.code);
|
||||
expect(result.data).toEqual("F00BAA");
|
||||
expect(result.code).toBeFalsy();
|
||||
// console.log("Raw log:", result.logs);
|
||||
const logs = parseLogs(result.logs);
|
||||
const wasmEvent = logs.find(() => true)?.events.find((e) => e.type === "wasm");
|
||||
@ -335,7 +335,7 @@ describe("wasm", () => {
|
||||
// upload data
|
||||
const hackatom = getHackatom();
|
||||
const result = await uploadContract(client, wallet, hackatom);
|
||||
expect(result.code).toBeFalsy();
|
||||
assert(!result.code);
|
||||
const logs = parseLogs(result.logs);
|
||||
const codeIdAttr = findAttribute(logs, "message", "code_id");
|
||||
const codeId = Number.parseInt(codeIdAttr.value, 10);
|
||||
@ -365,12 +365,7 @@ describe("wasm", () => {
|
||||
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
|
||||
const client = makeWasmClient(wasmd.endpoint);
|
||||
const beneficiaryAddress = makeRandomAddress();
|
||||
const transferAmount: readonly Coin[] = [
|
||||
{
|
||||
amount: "707707",
|
||||
denom: "ucosm",
|
||||
},
|
||||
];
|
||||
const transferAmount = coins(707707, "ucosm");
|
||||
|
||||
// reuse an existing contract, or upload if needed
|
||||
let codeId: number;
|
||||
@ -379,7 +374,7 @@ describe("wasm", () => {
|
||||
codeId = existingInfos[existingInfos.length - 1].id;
|
||||
} else {
|
||||
const uploadResult = await uploadContract(client, wallet, getHackatom());
|
||||
expect(uploadResult.code).toBeFalsy();
|
||||
assert(!uploadResult.code);
|
||||
const uploadLogs = parseLogs(uploadResult.logs);
|
||||
const codeIdAttr = findAttribute(uploadLogs, "message", "code_id");
|
||||
codeId = Number.parseInt(codeIdAttr.value, 10);
|
||||
@ -395,7 +390,7 @@ describe("wasm", () => {
|
||||
}
|
||||
|
||||
const result = await instantiateContract(client, wallet, codeId, beneficiaryAddress, transferAmount);
|
||||
expect(result.code).toBeFalsy();
|
||||
assert(!result.code);
|
||||
const logs = parseLogs(result.logs);
|
||||
const contractAddressAttr = findAttribute(logs, "message", "contract_address");
|
||||
const myAddress = contractAddressAttr.value;
|
||||
@ -418,9 +413,6 @@ describe("wasm", () => {
|
||||
jasmine.objectContaining({
|
||||
code_id: codeId,
|
||||
creator: alice.address0,
|
||||
init_msg: jasmine.objectContaining({
|
||||
beneficiary: beneficiaryAddress,
|
||||
}),
|
||||
}),
|
||||
);
|
||||
expect(myInfo.admin).toBeUndefined();
|
||||
@ -430,6 +422,49 @@ describe("wasm", () => {
|
||||
expect(await client.wasm.getContractInfo(nonExistentAddress)).toBeNull();
|
||||
});
|
||||
|
||||
it("can list contract history", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
|
||||
const client = makeWasmClient(wasmd.endpoint);
|
||||
const beneficiaryAddress = makeRandomAddress();
|
||||
const transferAmount = coins(707707, "ucosm");
|
||||
|
||||
// reuse an existing contract, or upload if needed
|
||||
let codeId: number;
|
||||
const existingInfos = await client.wasm.listCodeInfo();
|
||||
if (existingInfos.length > 0) {
|
||||
codeId = existingInfos[existingInfos.length - 1].id;
|
||||
} else {
|
||||
const uploadResult = await uploadContract(client, wallet, getHackatom());
|
||||
assert(!uploadResult.code);
|
||||
const uploadLogs = parseLogs(uploadResult.logs);
|
||||
const codeIdAttr = findAttribute(uploadLogs, "message", "code_id");
|
||||
codeId = Number.parseInt(codeIdAttr.value, 10);
|
||||
}
|
||||
|
||||
// create new instance and compare before and after
|
||||
const result = await instantiateContract(client, wallet, codeId, beneficiaryAddress, transferAmount);
|
||||
assert(!result.code);
|
||||
const logs = parseLogs(result.logs);
|
||||
const contractAddressAttr = findAttribute(logs, "message", "contract_address");
|
||||
const myAddress = contractAddressAttr.value;
|
||||
|
||||
// check out history
|
||||
const myHistory = await client.wasm.getContractCodeHistory(myAddress);
|
||||
assert(myHistory);
|
||||
expect(myHistory).toContain({
|
||||
code_id: codeId,
|
||||
operation: "Init",
|
||||
msg: {
|
||||
verifier: alice.address0,
|
||||
beneficiary: beneficiaryAddress,
|
||||
},
|
||||
});
|
||||
// make sure random addresses don't give useful info
|
||||
const nonExistentAddress = makeRandomAddress();
|
||||
expect(await client.wasm.getContractCodeHistory(nonExistentAddress)).toBeNull();
|
||||
});
|
||||
|
||||
describe("contract state", () => {
|
||||
const client = makeWasmClient(wasmd.endpoint);
|
||||
const noContract = makeRandomAddress();
|
||||
@ -453,9 +488,10 @@ describe("wasm", () => {
|
||||
|
||||
it("can get all state", async () => {
|
||||
pendingWithoutWasmd();
|
||||
assert(contractAddress);
|
||||
|
||||
// get contract state
|
||||
const state = await client.wasm.getAllContractState(contractAddress!);
|
||||
const state = await client.wasm.getAllContractState(contractAddress);
|
||||
expect(state.length).toEqual(1);
|
||||
const data = state[0];
|
||||
expect(data.key).toEqual(expectedKey);
|
||||
@ -470,16 +506,17 @@ describe("wasm", () => {
|
||||
|
||||
it("can query by key", async () => {
|
||||
pendingWithoutWasmd();
|
||||
assert(contractAddress);
|
||||
|
||||
// query by one key
|
||||
const raw = await client.wasm.queryContractRaw(contractAddress!, expectedKey);
|
||||
const raw = await client.wasm.queryContractRaw(contractAddress, expectedKey);
|
||||
assert(raw, "must get result");
|
||||
const model = JSON.parse(fromAscii(raw));
|
||||
expect(model.verifier).toBeDefined();
|
||||
expect(model.beneficiary).toBeDefined();
|
||||
|
||||
// missing key is null
|
||||
const missing = await client.wasm.queryContractRaw(contractAddress!, fromHex("cafe0dad"));
|
||||
const missing = await client.wasm.queryContractRaw(contractAddress, fromHex("cafe0dad"));
|
||||
expect(missing).toBeNull();
|
||||
|
||||
// bad address is null
|
||||
@ -489,13 +526,14 @@ describe("wasm", () => {
|
||||
|
||||
it("can make smart queries", async () => {
|
||||
pendingWithoutWasmd();
|
||||
assert(contractAddress);
|
||||
|
||||
// we can query the verifier properly
|
||||
const resultDocument = await client.wasm.queryContractSmart(contractAddress!, { verifier: {} });
|
||||
const resultDocument = await client.wasm.queryContractSmart(contractAddress, { verifier: {} });
|
||||
expect(resultDocument).toEqual({ verifier: alice.address0 });
|
||||
|
||||
// invalid query syntax throws an error
|
||||
await client.wasm.queryContractSmart(contractAddress!, { nosuchkey: {} }).then(
|
||||
await client.wasm.queryContractSmart(contractAddress, { nosuchkey: {} }).then(
|
||||
() => fail("shouldn't succeed"),
|
||||
(error) =>
|
||||
expect(error).toMatch(/query wasm contract failed: parsing hackatom::contract::QueryMsg/),
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { fromBase64, fromUtf8, toHex, toUtf8 } from "@cosmjs/encoding";
|
||||
import { LcdApiArray, LcdClient, normalizeLcdApiArray } from "@cosmjs/sdk38";
|
||||
import { LcdApiArray, LcdClient, normalizeLcdApiArray } from "@cosmjs/launchpad";
|
||||
|
||||
import { JsonObject, Model, parseWasmData, WasmData } from "../types";
|
||||
|
||||
@ -52,9 +52,12 @@ export interface ContractInfo {
|
||||
readonly label: string;
|
||||
}
|
||||
|
||||
export interface ContractDetails extends ContractInfo {
|
||||
/** Argument passed on initialization of the contract */
|
||||
readonly init_msg: object;
|
||||
// An entry in the contracts code/ migration history
|
||||
export interface ContractCodeHistoryEntry {
|
||||
// operation can be "Init", "Migrate", "Genesis"
|
||||
readonly operation: string;
|
||||
readonly code_id: number;
|
||||
readonly msg: object;
|
||||
}
|
||||
|
||||
interface SmartQueryResponse {
|
||||
@ -92,7 +95,7 @@ export interface WasmExtension {
|
||||
/**
|
||||
* Returns null when contract was not found at this address.
|
||||
*/
|
||||
readonly getContractInfo: (address: string) => Promise<ContractDetails | null>;
|
||||
readonly getContractInfo: (address: string) => Promise<ContractInfo | null>;
|
||||
|
||||
/**
|
||||
* Returns all contract state.
|
||||
@ -111,6 +114,11 @@ export interface WasmExtension {
|
||||
* Throws error if no such contract exists, the query format is invalid or the response is invalid.
|
||||
*/
|
||||
readonly queryContractSmart: (address: string, query: object) => Promise<JsonObject>;
|
||||
|
||||
/**
|
||||
* Returns null when contract history was not found for this address.
|
||||
*/
|
||||
readonly getContractCodeHistory: (address: string) => Promise<ContractCodeHistoryEntry[] | null>;
|
||||
};
|
||||
}
|
||||
|
||||
@ -134,7 +142,12 @@ export function setupWasmExtension(base: LcdClient): WasmExtension {
|
||||
},
|
||||
getContractInfo: async (address: string) => {
|
||||
const path = `/wasm/contract/${address}`;
|
||||
const response = (await base.get(path)) as WasmResponse<ContractDetails | null>;
|
||||
const response = (await base.get(path)) as WasmResponse<ContractInfo | null>;
|
||||
return unwrapWasmResponse(response);
|
||||
},
|
||||
getContractCodeHistory: async (address: string) => {
|
||||
const path = `/wasm/contract/${address}/history`;
|
||||
const response = (await base.get(path)) as WasmResponse<ContractCodeHistoryEntry[] | null>;
|
||||
return unwrapWasmResponse(response);
|
||||
},
|
||||
getAllContractState: async (address: string) => {
|
||||
|
@ -1,14 +1,20 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { Coin, Msg } from "@cosmjs/sdk38";
|
||||
import { Coin, Msg } from "@cosmjs/launchpad";
|
||||
|
||||
// TODO: implement
|
||||
/**
|
||||
* @see https://github.com/CosmWasm/wasmd/blob/v0.10.0-alpha/x/wasm/internal/types/params.go#L68-L71
|
||||
*/
|
||||
export type AccessConfig = never;
|
||||
|
||||
/**
|
||||
* Uploads Wasm code to the chain.
|
||||
* A numeric, auto-incrementing code ID will be generated as a result of the execution of this message.
|
||||
*
|
||||
* @see https://github.com/CosmWasm/wasmd/blob/v0.9.0-alpha4/x/wasm/internal/types/msg.go#L34
|
||||
* @see https://github.com/CosmWasm/wasmd/blob/v0.10.0-alpha/x/wasm/internal/types/msg.go#L10-L20
|
||||
*/
|
||||
export interface MsgStoreCode extends Msg {
|
||||
readonly type: "wasm/store-code";
|
||||
readonly type: "wasm/MsgStoreCode";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
@ -18,11 +24,12 @@ export interface MsgStoreCode extends Msg {
|
||||
readonly source: string;
|
||||
/** A docker tag. Can be empty. */
|
||||
readonly builder: string;
|
||||
readonly instantiate_permission?: AccessConfig;
|
||||
};
|
||||
}
|
||||
|
||||
export function isMsgStoreCode(msg: Msg): msg is MsgStoreCode {
|
||||
return (msg as MsgStoreCode).type === "wasm/store-code";
|
||||
return (msg as MsgStoreCode).type === "wasm/MsgStoreCode";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -32,7 +39,7 @@ export function isMsgStoreCode(msg: Msg): msg is MsgStoreCode {
|
||||
* @see https://github.com/CosmWasm/wasmd/blob/v0.9.0-alpha4/x/wasm/internal/types/msg.go#L104
|
||||
*/
|
||||
export interface MsgInstantiateContract extends Msg {
|
||||
readonly type: "wasm/instantiate";
|
||||
readonly type: "wasm/MsgInstantiateContract";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
@ -49,7 +56,7 @@ export interface MsgInstantiateContract extends Msg {
|
||||
}
|
||||
|
||||
export function isMsgInstantiateContract(msg: Msg): msg is MsgInstantiateContract {
|
||||
return (msg as MsgInstantiateContract).type === "wasm/instantiate";
|
||||
return (msg as MsgInstantiateContract).type === "wasm/MsgInstantiateContract";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,7 +65,7 @@ export function isMsgInstantiateContract(msg: Msg): msg is MsgInstantiateContrac
|
||||
* @see https://github.com/CosmWasm/wasmd/blob/v0.9.0-beta/x/wasm/internal/types/msg.go#L231
|
||||
*/
|
||||
export interface MsgUpdateAdmin extends Msg {
|
||||
readonly type: "wasm/update-contract-admin";
|
||||
readonly type: "wasm/MsgUpdateAdmin";
|
||||
readonly value: {
|
||||
/** Bech32-encoded sender address. This must be the old admin. */
|
||||
readonly sender: string;
|
||||
@ -70,7 +77,7 @@ export interface MsgUpdateAdmin extends Msg {
|
||||
}
|
||||
|
||||
export function isMsgUpdateAdmin(msg: Msg): msg is MsgUpdateAdmin {
|
||||
return (msg as MsgUpdateAdmin).type === "wasm/update-contract-admin";
|
||||
return (msg as MsgUpdateAdmin).type === "wasm/MsgUpdateAdmin";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,7 +86,7 @@ export function isMsgUpdateAdmin(msg: Msg): msg is MsgUpdateAdmin {
|
||||
* @see https://github.com/CosmWasm/wasmd/blob/v0.9.0-beta/x/wasm/internal/types/msg.go#L269
|
||||
*/
|
||||
export interface MsgClearAdmin extends Msg {
|
||||
readonly type: "wasm/clear-contract-admin";
|
||||
readonly type: "wasm/MsgClearAdmin";
|
||||
readonly value: {
|
||||
/** Bech32-encoded sender address. This must be the old admin. */
|
||||
readonly sender: string;
|
||||
@ -89,7 +96,7 @@ export interface MsgClearAdmin extends Msg {
|
||||
}
|
||||
|
||||
export function isMsgClearAdmin(msg: Msg): msg is MsgClearAdmin {
|
||||
return (msg as MsgClearAdmin).type === "wasm/clear-contract-admin";
|
||||
return (msg as MsgClearAdmin).type === "wasm/MsgClearAdmin";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -99,7 +106,7 @@ export function isMsgClearAdmin(msg: Msg): msg is MsgClearAdmin {
|
||||
* @see https://github.com/CosmWasm/wasmd/blob/v0.9.0-alpha4/x/wasm/internal/types/msg.go#L158
|
||||
*/
|
||||
export interface MsgExecuteContract extends Msg {
|
||||
readonly type: "wasm/execute";
|
||||
readonly type: "wasm/MsgExecuteContract";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
@ -112,7 +119,7 @@ export interface MsgExecuteContract extends Msg {
|
||||
}
|
||||
|
||||
export function isMsgExecuteContract(msg: Msg): msg is MsgExecuteContract {
|
||||
return (msg as MsgExecuteContract).type === "wasm/execute";
|
||||
return (msg as MsgExecuteContract).type === "wasm/MsgExecuteContract";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,7 +128,7 @@ export function isMsgExecuteContract(msg: Msg): msg is MsgExecuteContract {
|
||||
* @see https://github.com/CosmWasm/wasmd/blob/v0.9.0-alpha4/x/wasm/internal/types/msg.go#L195
|
||||
*/
|
||||
export interface MsgMigrateContract extends Msg {
|
||||
readonly type: "wasm/migrate";
|
||||
readonly type: "wasm/MsgMigrateContract";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
@ -135,5 +142,5 @@ export interface MsgMigrateContract extends Msg {
|
||||
}
|
||||
|
||||
export function isMsgMigrateContract(msg: Msg): msg is MsgMigrateContract {
|
||||
return (msg as MsgMigrateContract).type === "wasm/migrate";
|
||||
return (msg as MsgMigrateContract).type === "wasm/MsgMigrateContract";
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import {
|
||||
MsgDelegate,
|
||||
Secp256k1Wallet,
|
||||
setupAuthExtension,
|
||||
} from "@cosmjs/sdk38";
|
||||
} from "@cosmjs/launchpad";
|
||||
import { assert } from "@cosmjs/utils";
|
||||
|
||||
import { PrivateCosmWasmClient } from "./cosmwasmclient";
|
||||
|
@ -1,7 +1,6 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { Sha256 } from "@cosmjs/crypto";
|
||||
import { toBase64, toHex } from "@cosmjs/encoding";
|
||||
import { Uint53 } from "@cosmjs/math";
|
||||
import {
|
||||
BroadcastMode,
|
||||
Coin,
|
||||
@ -16,7 +15,8 @@ import {
|
||||
StdFee,
|
||||
StdSignature,
|
||||
StdTx,
|
||||
} from "@cosmjs/sdk38";
|
||||
} from "@cosmjs/launchpad";
|
||||
import { Uint53 } from "@cosmjs/math";
|
||||
import pako from "pako";
|
||||
|
||||
import { isValidBuilder } from "./builder";
|
||||
@ -208,7 +208,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
|
||||
const compressed = pako.gzip(wasmCode, { level: 9 });
|
||||
const storeCodeMsg: MsgStoreCode = {
|
||||
type: "wasm/store-code",
|
||||
type: "wasm/MsgStoreCode",
|
||||
value: {
|
||||
sender: this.senderAddress,
|
||||
wasm_byte_code: toBase64(compressed),
|
||||
@ -239,7 +239,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
options: InstantiateOptions = {},
|
||||
): Promise<InstantiateResult> {
|
||||
const instantiateMsg: MsgInstantiateContract = {
|
||||
type: "wasm/instantiate",
|
||||
type: "wasm/MsgInstantiateContract",
|
||||
value: {
|
||||
sender: this.senderAddress,
|
||||
code_id: new Uint53(codeId).toString(),
|
||||
@ -263,7 +263,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
|
||||
public async updateAdmin(contractAddress: string, newAdmin: string, memo = ""): Promise<ChangeAdminResult> {
|
||||
const updateAdminMsg: MsgUpdateAdmin = {
|
||||
type: "wasm/update-contract-admin",
|
||||
type: "wasm/MsgUpdateAdmin",
|
||||
value: {
|
||||
sender: this.senderAddress,
|
||||
contract: contractAddress,
|
||||
@ -282,7 +282,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
|
||||
public async clearAdmin(contractAddress: string, memo = ""): Promise<ChangeAdminResult> {
|
||||
const clearAdminMsg: MsgClearAdmin = {
|
||||
type: "wasm/clear-contract-admin",
|
||||
type: "wasm/MsgClearAdmin",
|
||||
value: {
|
||||
sender: this.senderAddress,
|
||||
contract: contractAddress,
|
||||
@ -305,7 +305,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
memo = "",
|
||||
): Promise<MigrateResult> {
|
||||
const msg: MsgMigrateContract = {
|
||||
type: "wasm/migrate",
|
||||
type: "wasm/MsgMigrateContract",
|
||||
value: {
|
||||
sender: this.senderAddress,
|
||||
contract: contractAddress,
|
||||
@ -330,7 +330,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
transferAmount?: readonly Coin[],
|
||||
): Promise<ExecuteResult> {
|
||||
const executeMsg: MsgExecuteContract = {
|
||||
type: "wasm/execute",
|
||||
type: "wasm/MsgExecuteContract",
|
||||
value: {
|
||||
sender: this.senderAddress,
|
||||
contract: contractAddress,
|
||||
|
4
packages/cosmwasm/src/testdata/contract.json
vendored
4
packages/cosmwasm/src/testdata/contract.json
vendored
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
||||
import { Random } from "@cosmjs/crypto";
|
||||
import { Bech32, fromBase64 } from "@cosmjs/encoding";
|
||||
import { Msg, StdFee, StdSignature, StdTx } from "@cosmjs/sdk38";
|
||||
import { Msg, StdFee, StdSignature, StdTx } from "@cosmjs/launchpad";
|
||||
|
||||
import hackatom from "./testdata/contract.json";
|
||||
|
||||
@ -32,9 +32,9 @@ export const bech32AddressMatcher = /^[\x21-\x7e]{1,83}1[02-9ac-hj-np-z]{38}$/;
|
||||
/** Deployed as part of scripts/wasmd/init.sh */
|
||||
export const deployedErc20 = {
|
||||
codeId: 1,
|
||||
source: "https://crates.io/api/v1/crates/cw-erc20/0.5.1/download",
|
||||
builder: "cosmwasm/rust-optimizer:0.8.0",
|
||||
checksum: "3e97bf88bd960fee5e5959c77b972eb2927690bc10160792741b174f105ec0c5",
|
||||
source: "https://crates.io/api/v1/crates/cw-erc20/not-yet-released/download",
|
||||
builder: "cosmwasm/rust-optimizer:0.9.0",
|
||||
checksum: "0f14abcc6fed08f2dd06896db974989db97dbcc6e8e30188b73fe5ab427c7785",
|
||||
instances: [
|
||||
"cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5", // HASH
|
||||
"cosmos1hqrdl6wstt8qzshwc6mrumpjk9338k0lr4dqxd", // ISA
|
||||
@ -47,7 +47,7 @@ export const wasmd = {
|
||||
chainId: "testing",
|
||||
};
|
||||
|
||||
export const validatorAddress = "cosmosvaloper1gjvanqxc774u6ed9thj4gpn9gj5zus5u32enqn";
|
||||
export const validatorAddress = "cosmosvaloper1fa7hj49pf8uzc4m0lw5swjhhl5th2484gvnlpv";
|
||||
|
||||
export const alice = {
|
||||
mnemonic: "enlist hip relief stomach skate base shallow young switch frequent cry park",
|
||||
|
15
packages/cosmwasm/types/cosmwasmclient.d.ts
vendored
15
packages/cosmwasm/types/cosmwasmclient.d.ts
vendored
@ -8,7 +8,7 @@ import {
|
||||
PostTxResult,
|
||||
PubKey,
|
||||
StdTx,
|
||||
} from "@cosmjs/sdk38";
|
||||
} from "@cosmjs/launchpad";
|
||||
import { WasmExtension } from "./lcdapi/wasm";
|
||||
import { JsonObject } from "./types";
|
||||
export interface GetSequenceResult {
|
||||
@ -84,9 +84,10 @@ export interface Contract {
|
||||
readonly admin: string | undefined;
|
||||
readonly label: string;
|
||||
}
|
||||
export interface ContractDetails extends Contract {
|
||||
/** Argument passed on initialization of the contract */
|
||||
readonly initMsg: object;
|
||||
export interface ContractCodeHistoryEntry {
|
||||
readonly operation: string;
|
||||
readonly codeId: number;
|
||||
readonly msg: object;
|
||||
}
|
||||
export interface BlockHeader {
|
||||
readonly version: {
|
||||
@ -154,7 +155,11 @@ export declare class CosmWasmClient {
|
||||
/**
|
||||
* Throws an error if no contract was found at the address
|
||||
*/
|
||||
getContract(address: string): Promise<ContractDetails>;
|
||||
getContract(address: string): Promise<Contract>;
|
||||
/**
|
||||
* Throws an error if no contract was found at the address
|
||||
*/
|
||||
getContractCodeHistory(address: string): Promise<readonly ContractCodeHistoryEntry[]>;
|
||||
/**
|
||||
* Returns the data at the key if present (raw contract dependent storage data)
|
||||
* or null if no data at this key.
|
||||
|
2
packages/cosmwasm/types/index.d.ts
vendored
2
packages/cosmwasm/types/index.d.ts
vendored
@ -8,7 +8,7 @@ export {
|
||||
Code,
|
||||
CodeDetails,
|
||||
Contract,
|
||||
ContractDetails,
|
||||
ContractCodeHistoryEntry,
|
||||
CosmWasmClient,
|
||||
GetSequenceResult,
|
||||
SearchByHeightQuery,
|
||||
|
15
packages/cosmwasm/types/lcdapi/wasm.d.ts
vendored
15
packages/cosmwasm/types/lcdapi/wasm.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
import { LcdClient } from "@cosmjs/sdk38";
|
||||
import { LcdClient } from "@cosmjs/launchpad";
|
||||
import { JsonObject, Model } from "../types";
|
||||
export interface CodeInfo {
|
||||
readonly id: number;
|
||||
@ -33,9 +33,10 @@ export interface ContractInfo {
|
||||
readonly admin?: string;
|
||||
readonly label: string;
|
||||
}
|
||||
export interface ContractDetails extends ContractInfo {
|
||||
/** Argument passed on initialization of the contract */
|
||||
readonly init_msg: object;
|
||||
export interface ContractCodeHistoryEntry {
|
||||
readonly operation: string;
|
||||
readonly code_id: number;
|
||||
readonly msg: object;
|
||||
}
|
||||
/**
|
||||
* @see https://github.com/cosmwasm/wasmd/blob/master/x/wasm/client/rest/query.go#L19-L27
|
||||
@ -53,7 +54,7 @@ export interface WasmExtension {
|
||||
/**
|
||||
* Returns null when contract was not found at this address.
|
||||
*/
|
||||
readonly getContractInfo: (address: string) => Promise<ContractDetails | null>;
|
||||
readonly getContractInfo: (address: string) => Promise<ContractInfo | null>;
|
||||
/**
|
||||
* Returns all contract state.
|
||||
* This is an empty array if no such contract, or contract has no data.
|
||||
@ -69,6 +70,10 @@ export interface WasmExtension {
|
||||
* Throws error if no such contract exists, the query format is invalid or the response is invalid.
|
||||
*/
|
||||
readonly queryContractSmart: (address: string, query: object) => Promise<JsonObject>;
|
||||
/**
|
||||
* Returns null when contract history was not found for this address.
|
||||
*/
|
||||
readonly getContractCodeHistory: (address: string) => Promise<ContractCodeHistoryEntry[] | null>;
|
||||
};
|
||||
}
|
||||
export declare function setupWasmExtension(base: LcdClient): WasmExtension;
|
||||
|
21
packages/cosmwasm/types/msgs.d.ts
vendored
21
packages/cosmwasm/types/msgs.d.ts
vendored
@ -1,12 +1,16 @@
|
||||
import { Coin, Msg } from "@cosmjs/sdk38";
|
||||
import { Coin, Msg } from "@cosmjs/launchpad";
|
||||
/**
|
||||
* @see https://github.com/CosmWasm/wasmd/blob/v0.10.0-alpha/x/wasm/internal/types/params.go#L68-L71
|
||||
*/
|
||||
export declare type AccessConfig = never;
|
||||
/**
|
||||
* Uploads Wasm code to the chain.
|
||||
* A numeric, auto-incrementing code ID will be generated as a result of the execution of this message.
|
||||
*
|
||||
* @see https://github.com/CosmWasm/wasmd/blob/v0.9.0-alpha4/x/wasm/internal/types/msg.go#L34
|
||||
* @see https://github.com/CosmWasm/wasmd/blob/v0.10.0-alpha/x/wasm/internal/types/msg.go#L10-L20
|
||||
*/
|
||||
export interface MsgStoreCode extends Msg {
|
||||
readonly type: "wasm/store-code";
|
||||
readonly type: "wasm/MsgStoreCode";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
@ -16,6 +20,7 @@ export interface MsgStoreCode extends Msg {
|
||||
readonly source: string;
|
||||
/** A docker tag. Can be empty. */
|
||||
readonly builder: string;
|
||||
readonly instantiate_permission?: AccessConfig;
|
||||
};
|
||||
}
|
||||
export declare function isMsgStoreCode(msg: Msg): msg is MsgStoreCode;
|
||||
@ -26,7 +31,7 @@ export declare function isMsgStoreCode(msg: Msg): msg is MsgStoreCode;
|
||||
* @see https://github.com/CosmWasm/wasmd/blob/v0.9.0-alpha4/x/wasm/internal/types/msg.go#L104
|
||||
*/
|
||||
export interface MsgInstantiateContract extends Msg {
|
||||
readonly type: "wasm/instantiate";
|
||||
readonly type: "wasm/MsgInstantiateContract";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
@ -48,7 +53,7 @@ export declare function isMsgInstantiateContract(msg: Msg): msg is MsgInstantiat
|
||||
* @see https://github.com/CosmWasm/wasmd/blob/v0.9.0-beta/x/wasm/internal/types/msg.go#L231
|
||||
*/
|
||||
export interface MsgUpdateAdmin extends Msg {
|
||||
readonly type: "wasm/update-contract-admin";
|
||||
readonly type: "wasm/MsgUpdateAdmin";
|
||||
readonly value: {
|
||||
/** Bech32-encoded sender address. This must be the old admin. */
|
||||
readonly sender: string;
|
||||
@ -65,7 +70,7 @@ export declare function isMsgUpdateAdmin(msg: Msg): msg is MsgUpdateAdmin;
|
||||
* @see https://github.com/CosmWasm/wasmd/blob/v0.9.0-beta/x/wasm/internal/types/msg.go#L269
|
||||
*/
|
||||
export interface MsgClearAdmin extends Msg {
|
||||
readonly type: "wasm/clear-contract-admin";
|
||||
readonly type: "wasm/MsgClearAdmin";
|
||||
readonly value: {
|
||||
/** Bech32-encoded sender address. This must be the old admin. */
|
||||
readonly sender: string;
|
||||
@ -81,7 +86,7 @@ export declare function isMsgClearAdmin(msg: Msg): msg is MsgClearAdmin;
|
||||
* @see https://github.com/CosmWasm/wasmd/blob/v0.9.0-alpha4/x/wasm/internal/types/msg.go#L158
|
||||
*/
|
||||
export interface MsgExecuteContract extends Msg {
|
||||
readonly type: "wasm/execute";
|
||||
readonly type: "wasm/MsgExecuteContract";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
@ -99,7 +104,7 @@ export declare function isMsgExecuteContract(msg: Msg): msg is MsgExecuteContrac
|
||||
* @see https://github.com/CosmWasm/wasmd/blob/v0.9.0-alpha4/x/wasm/internal/types/msg.go#L195
|
||||
*/
|
||||
export interface MsgMigrateContract extends Msg {
|
||||
readonly type: "wasm/migrate";
|
||||
readonly type: "wasm/MsgMigrateContract";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
|
@ -1,4 +1,12 @@
|
||||
import { BroadcastMode, Coin, Msg, OfflineSigner, PostTxResult, StdFee, StdSignature } from "@cosmjs/sdk38";
|
||||
import {
|
||||
BroadcastMode,
|
||||
Coin,
|
||||
Msg,
|
||||
OfflineSigner,
|
||||
PostTxResult,
|
||||
StdFee,
|
||||
StdSignature,
|
||||
} from "@cosmjs/launchpad";
|
||||
import { Account, CosmWasmClient, GetSequenceResult } from "./cosmwasmclient";
|
||||
import { Log } from "./logs";
|
||||
export interface SigningCallback {
|
||||
|
@ -35,6 +35,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@cosmjs/cosmwasm": "^0.21.1",
|
||||
"@cosmjs/sdk38": "^0.21.1"
|
||||
"@cosmjs/launchpad": "^0.21.1"
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm";
|
||||
import { Coin, coins, makeCosmoshubPath, Secp256k1Wallet } from "@cosmjs/sdk38";
|
||||
import { Coin, coins, makeCosmoshubPath, Secp256k1Wallet } from "@cosmjs/launchpad";
|
||||
|
||||
import {
|
||||
BalanceResponse,
|
||||
@ -31,7 +31,7 @@ const params = {
|
||||
name: "Bounty",
|
||||
symbol: "BOUNTY",
|
||||
decimals: 3,
|
||||
validator: "cosmosvaloper1gjvanqxc774u6ed9thj4gpn9gj5zus5u32enqn",
|
||||
validator: "cosmosvaloper1fa7hj49pf8uzc4m0lw5swjhhl5th2484gvnlpv",
|
||||
exitTax: "0.005", // 0.5 %
|
||||
minWithdrawal: "700",
|
||||
};
|
||||
|
@ -36,8 +36,8 @@
|
||||
"dependencies": {
|
||||
"@cosmjs/crypto": "^0.21.1",
|
||||
"@cosmjs/encoding": "^0.21.1",
|
||||
"@cosmjs/launchpad": "^0.21.1",
|
||||
"@cosmjs/math": "^0.21.1",
|
||||
"@cosmjs/sdk38": "^0.21.1",
|
||||
"@cosmjs/utils": "^0.21.1",
|
||||
"@koa/cors": "^3.0.0",
|
||||
"koa": "^2.11.0",
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { CosmosClient } from "@cosmjs/sdk38";
|
||||
import { CosmosClient } from "@cosmjs/launchpad";
|
||||
|
||||
import { Webserver } from "../../api/webserver";
|
||||
import * as constants from "../../constants";
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Coin } from "@cosmjs/launchpad";
|
||||
import { Decimal } from "@cosmjs/math";
|
||||
import { Coin } from "@cosmjs/sdk38";
|
||||
|
||||
import { MinimalAccount, SendJob, TokenConfiguration } from "./types";
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Random } from "@cosmjs/crypto";
|
||||
import { Bech32 } from "@cosmjs/encoding";
|
||||
import { CosmosClient } from "@cosmjs/sdk38";
|
||||
import { CosmosClient } from "@cosmjs/launchpad";
|
||||
import { assert } from "@cosmjs/utils";
|
||||
|
||||
import { Faucet } from "./faucet";
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { CosmosClient, OfflineSigner, SigningCosmosClient } from "@cosmjs/sdk38";
|
||||
import { CosmosClient, OfflineSigner, SigningCosmosClient } from "@cosmjs/launchpad";
|
||||
import { sleep } from "@cosmjs/utils";
|
||||
|
||||
import { debugAccount, logAccountsState, logSendJob } from "./debugging";
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { pathToString } from "@cosmjs/crypto";
|
||||
import { makeCosmoshubPath, OfflineSigner, Secp256k1Wallet } from "@cosmjs/sdk38";
|
||||
import { makeCosmoshubPath, OfflineSigner, Secp256k1Wallet } from "@cosmjs/launchpad";
|
||||
|
||||
export async function createWallets(
|
||||
mnemonic: string,
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Coin } from "@cosmjs/launchpad";
|
||||
import { Decimal, Uint53 } from "@cosmjs/math";
|
||||
import { Coin } from "@cosmjs/sdk38";
|
||||
|
||||
import { BankTokenMeta, MinimalAccount, TokenConfiguration } from "./types";
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Account, Coin } from "@cosmjs/sdk38";
|
||||
import { Account, Coin } from "@cosmjs/launchpad";
|
||||
|
||||
export interface SendJob {
|
||||
readonly sender: string;
|
||||
|
14
packages/launchpad/README.md
Normal file
14
packages/launchpad/README.md
Normal file
@ -0,0 +1,14 @@
|
||||
# @cosmjs/launchpad
|
||||
|
||||
[](https://www.npmjs.com/package/@cosmjs/launchpad)
|
||||
|
||||
A client library for the Cosmos SDK 0.37 (cosmoshub-3), 0.38 and 0.39
|
||||
(Launchpad). See the article
|
||||
[Launchpad — A pre-stargate stable version of the Cosmos SDK](https://blog.cosmos.network/launchpad-a-pre-stargate-stable-version-of-the-cosmos-sdk-e0c58d8c4e24)
|
||||
to learn more about launchpad.
|
||||
|
||||
## License
|
||||
|
||||
This package is part of the cosmjs repository, licensed under the Apache License
|
||||
2.0 (see [NOTICE](https://github.com/CosmWasm/cosmjs/blob/master/NOTICE) and
|
||||
[LICENSE](https://github.com/CosmWasm/cosmjs/blob/master/LICENSE)).
|
@ -1,8 +1,11 @@
|
||||
{
|
||||
"name": "@cosmjs/sdk38",
|
||||
"name": "@cosmjs/launchpad",
|
||||
"version": "0.21.1",
|
||||
"description": "Utilities for Cosmos SDK 0.38",
|
||||
"author": "Ethan Frey <ethanfrey@users.noreply.github.com>",
|
||||
"description": "A client library for the Cosmos SDK 0.37 (cosmoshub-3), 0.38 and 0.39 (Launchpad)",
|
||||
"contributors": [
|
||||
"Ethan Frey <ethanfrey@users.noreply.github.com>",
|
||||
"Simon Warta <webmaster128@users.noreply.github.com>"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"main": "build/index.js",
|
||||
"types": "types/index.d.ts",
|
||||
@ -15,7 +18,7 @@
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/CosmWasm/cosmjs/tree/master/packages/sdk38"
|
||||
"url": "https://github.com/CosmWasm/cosmjs/tree/master/packages/launchpad"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
@ -1,5 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { encodeBech32Pubkey } from "../pubkey";
|
||||
import {
|
||||
faucet,
|
||||
makeRandomAddress,
|
||||
@ -25,7 +24,7 @@ describe("AuthExtension", () => {
|
||||
type: "cosmos-sdk/Account",
|
||||
value: {
|
||||
address: unused.address,
|
||||
public_key: "", // not known to the chain
|
||||
public_key: null, // not known to the chain
|
||||
coins: [
|
||||
{
|
||||
amount: "1000000000",
|
||||
@ -36,8 +35,8 @@ describe("AuthExtension", () => {
|
||||
denom: "ustake",
|
||||
},
|
||||
],
|
||||
account_number: unused.accountNumber,
|
||||
sequence: 0,
|
||||
account_number: unused.accountNumber.toString(),
|
||||
sequence: unused.sequence.toString(),
|
||||
},
|
||||
});
|
||||
});
|
||||
@ -49,7 +48,7 @@ describe("AuthExtension", () => {
|
||||
const { result } = await client.auth.account(faucet.address);
|
||||
expect(result.value).toEqual(
|
||||
jasmine.objectContaining({
|
||||
public_key: encodeBech32Pubkey(faucet.pubkey, "cosmospub"),
|
||||
public_key: faucet.pubkey,
|
||||
}),
|
||||
);
|
||||
});
|
@ -16,6 +16,7 @@ import {
|
||||
nonNegativeIntegerMatcher,
|
||||
pendingWithoutWasmd,
|
||||
tendermintIdMatcher,
|
||||
unused,
|
||||
wasmd,
|
||||
wasmdEnabled,
|
||||
} from "../testutils.spec";
|
||||
@ -23,20 +24,7 @@ import { StdFee } from "../types";
|
||||
import { makeCosmoshubPath } from "../wallet";
|
||||
import { setupAuthExtension } from "./auth";
|
||||
import { TxsResponse } from "./base";
|
||||
import { LcdApiArray, LcdClient, normalizeLcdApiArray } from "./lcdclient";
|
||||
|
||||
/** Deployed as part of scripts/wasmd/init.sh */
|
||||
export const deployedErc20 = {
|
||||
codeId: 1,
|
||||
source: "https://crates.io/api/v1/crates/cw-erc20/0.5.1/download",
|
||||
builder: "cosmwasm/rust-optimizer:0.8.0",
|
||||
checksum: "3e97bf88bd960fee5e5959c77b972eb2927690bc10160792741b174f105ec0c5",
|
||||
instances: [
|
||||
"cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5", // HASH
|
||||
"cosmos1hqrdl6wstt8qzshwc6mrumpjk9338k0lr4dqxd", // ISA
|
||||
"cosmos18r5szma8hm93pvx6lwpjwyxruw27e0k5uw835c", // JADE
|
||||
],
|
||||
};
|
||||
import { LcdApiArray, LcdClient } from "./lcdclient";
|
||||
|
||||
describe("LcdClient", () => {
|
||||
const defaultRecipientAddress = makeRandomAddress();
|
||||
@ -47,51 +35,39 @@ describe("LcdClient", () => {
|
||||
});
|
||||
|
||||
describe("withModules", () => {
|
||||
interface CodeInfo {
|
||||
readonly id: number;
|
||||
/** Bech32 account address */
|
||||
readonly creator: string;
|
||||
/** Hex-encoded sha256 hash of the code stored here */
|
||||
readonly data_hash: string;
|
||||
readonly source?: string;
|
||||
readonly builder?: string;
|
||||
}
|
||||
|
||||
type WasmResponse<T> = WasmSuccess<T> | WasmError;
|
||||
|
||||
interface WasmSuccess<T> {
|
||||
interface TotalSupplyAllResponse {
|
||||
readonly height: string;
|
||||
readonly result: T;
|
||||
readonly result: LcdApiArray<Coin>;
|
||||
}
|
||||
|
||||
interface WasmError {
|
||||
readonly error: string;
|
||||
}
|
||||
|
||||
function isWasmError<T>(resp: WasmResponse<T>): resp is WasmError {
|
||||
return (resp as WasmError).error !== undefined;
|
||||
}
|
||||
|
||||
function unwrapWasmResponse<T>(response: WasmResponse<T>): T {
|
||||
if (isWasmError(response)) {
|
||||
throw new Error(response.error);
|
||||
}
|
||||
return response.result;
|
||||
}
|
||||
|
||||
interface WasmExtension {
|
||||
wasm: {
|
||||
listCodeInfo: () => Promise<readonly CodeInfo[]>;
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
function setupSupplyExtension(base: LcdClient) {
|
||||
return {
|
||||
supply: {
|
||||
totalAll: async (): Promise<TotalSupplyAllResponse> => {
|
||||
return base.get(`/supply/total`);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function setupWasmExtension(base: LcdClient): WasmExtension {
|
||||
interface BankBalancesResponse {
|
||||
readonly height: string;
|
||||
readonly result: readonly Coin[];
|
||||
}
|
||||
|
||||
interface BankExtension {
|
||||
readonly bank: {
|
||||
readonly balances: (address: string) => Promise<BankBalancesResponse>;
|
||||
};
|
||||
}
|
||||
|
||||
function setupBankExtension(base: LcdClient): BankExtension {
|
||||
return {
|
||||
wasm: {
|
||||
listCodeInfo: async (): Promise<readonly CodeInfo[]> => {
|
||||
const path = `/wasm/code`;
|
||||
const responseData = (await base.get(path)) as WasmResponse<LcdApiArray<CodeInfo>>;
|
||||
return normalizeLcdApiArray(unwrapWasmResponse(responseData));
|
||||
bank: {
|
||||
balances: async (address: string) => {
|
||||
const path = `/bank/balances/${address}`;
|
||||
return base.get(path);
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -105,60 +81,59 @@ describe("LcdClient", () => {
|
||||
it("works for one extension", async () => {
|
||||
pendingWithoutWasmd();
|
||||
|
||||
const client = LcdClient.withExtensions({ apiUrl: wasmd.endpoint }, setupWasmExtension);
|
||||
const codes = await client.wasm.listCodeInfo();
|
||||
expect(codes.length).toBeGreaterThanOrEqual(3);
|
||||
expect(codes[0].id).toEqual(deployedErc20.codeId);
|
||||
expect(codes[0].data_hash).toEqual(deployedErc20.checksum.toUpperCase());
|
||||
expect(codes[0].builder).toEqual(deployedErc20.builder);
|
||||
expect(codes[0].source).toEqual(deployedErc20.source);
|
||||
const client = LcdClient.withExtensions({ apiUrl: wasmd.endpoint }, setupSupplyExtension);
|
||||
const supply = await client.supply.totalAll();
|
||||
expect(supply).toEqual({
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: [
|
||||
{
|
||||
amount: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
denom: "ucosm",
|
||||
},
|
||||
{
|
||||
amount: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
denom: "ustake",
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("works for two extensions", async () => {
|
||||
pendingWithoutWasmd();
|
||||
|
||||
interface TotalSupplyAllResponse {
|
||||
readonly height: string;
|
||||
readonly result: LcdApiArray<Coin>;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
function setupSupplyExtension(base: LcdClient) {
|
||||
return {
|
||||
supply: {
|
||||
totalAll: async (): Promise<TotalSupplyAllResponse> => {
|
||||
const path = `/supply/total`;
|
||||
return (await base.get(path)) as TotalSupplyAllResponse;
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const client = LcdClient.withExtensions(
|
||||
{ apiUrl: wasmd.endpoint },
|
||||
setupWasmExtension,
|
||||
setupSupplyExtension,
|
||||
setupBankExtension,
|
||||
);
|
||||
const codes = await client.wasm.listCodeInfo();
|
||||
expect(codes.length).toBeGreaterThanOrEqual(3);
|
||||
expect(codes[0].id).toEqual(deployedErc20.codeId);
|
||||
expect(codes[0].data_hash).toEqual(deployedErc20.checksum.toUpperCase());
|
||||
expect(codes[0].builder).toEqual(deployedErc20.builder);
|
||||
expect(codes[0].source).toEqual(deployedErc20.source);
|
||||
const supply = await client.supply.totalAll();
|
||||
expect(supply).toEqual({
|
||||
height: jasmine.stringMatching(/^[0-9]+$/),
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: [
|
||||
{
|
||||
amount: jasmine.stringMatching(/^[0-9]+$/),
|
||||
amount: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
denom: "ucosm",
|
||||
},
|
||||
{
|
||||
amount: jasmine.stringMatching(/^[0-9]+$/),
|
||||
amount: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
denom: "ustake",
|
||||
},
|
||||
],
|
||||
});
|
||||
const balances = await client.bank.balances(unused.address);
|
||||
expect(balances).toEqual({
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: [
|
||||
{
|
||||
denom: "ucosm",
|
||||
amount: "1000000000",
|
||||
},
|
||||
{
|
||||
denom: "ustake",
|
||||
amount: "1000000000",
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("can merge two extensions into the same module", async () => {
|
@ -17,7 +17,7 @@ describe("SlashingExtension", () => {
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: [
|
||||
{
|
||||
address: "cosmosvalcons1yyjaavsv98lwn8he9lzcjhefzyyn4xygfyxls0",
|
||||
address: "cosmosvalcons1cw2p365mwycxuy89ml3crg96tqen7vvm0xgujv",
|
||||
start_height: "0",
|
||||
index_offset: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
jailed_until: "1970-01-01T00:00:00Z",
|
@ -10,6 +10,7 @@ import { SigningCosmosClient } from "../signingcosmosclient";
|
||||
import {
|
||||
bigDecimalMatcher,
|
||||
dateTimeStampMatcher,
|
||||
delegatorAddress,
|
||||
faucet,
|
||||
nonNegativeIntegerMatcher,
|
||||
pendingWithoutWasmd,
|
||||
@ -29,6 +30,9 @@ describe("StakingExtension", () => {
|
||||
amount: coins(25000, "ucosm"),
|
||||
gas: "1500000", // 1.5 million
|
||||
};
|
||||
const consensusPubkey =
|
||||
"cosmosvalconspub1zcjduepq4stq4qg03lj68gx2lh2rpmnlcjtt0ejk0n6y3fv8kdkftcg79tmqkj9lqs";
|
||||
const commissionUpdateTime = "2020-07-23T15:05:47.5072591Z";
|
||||
|
||||
beforeAll(async () => {
|
||||
if (wasmdEnabled()) {
|
||||
@ -149,8 +153,7 @@ describe("StakingExtension", () => {
|
||||
result: [
|
||||
{
|
||||
operator_address: validatorAddress,
|
||||
consensus_pubkey:
|
||||
"cosmosvalconspub1zcjduepqau36ht2r742jh230pxlu4wjmwcmkwpeqava80acphsu87vt5xlpqx6g7qh",
|
||||
consensus_pubkey: consensusPubkey,
|
||||
jailed: false,
|
||||
status: BondStatus.Bonded,
|
||||
tokens: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
@ -170,7 +173,7 @@ describe("StakingExtension", () => {
|
||||
max_rate: "0.200000000000000000",
|
||||
max_change_rate: "0.010000000000000000",
|
||||
},
|
||||
update_time: "2020-06-03T06:01:17.4747987Z",
|
||||
update_time: commissionUpdateTime,
|
||||
},
|
||||
min_self_delegation: "1",
|
||||
},
|
||||
@ -188,8 +191,7 @@ describe("StakingExtension", () => {
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: {
|
||||
operator_address: validatorAddress,
|
||||
consensus_pubkey:
|
||||
"cosmosvalconspub1zcjduepqau36ht2r742jh230pxlu4wjmwcmkwpeqava80acphsu87vt5xlpqx6g7qh",
|
||||
consensus_pubkey: consensusPubkey,
|
||||
jailed: false,
|
||||
status: BondStatus.Bonded,
|
||||
tokens: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
@ -209,7 +211,7 @@ describe("StakingExtension", () => {
|
||||
max_rate: "0.200000000000000000",
|
||||
max_change_rate: "0.010000000000000000",
|
||||
},
|
||||
update_time: "2020-06-03T06:01:17.4747987Z",
|
||||
update_time: commissionUpdateTime,
|
||||
},
|
||||
min_self_delegation: "1",
|
||||
},
|
||||
@ -279,8 +281,7 @@ describe("StakingExtension", () => {
|
||||
result: [
|
||||
{
|
||||
operator_address: validatorAddress,
|
||||
consensus_pubkey:
|
||||
"cosmosvalconspub1zcjduepqau36ht2r742jh230pxlu4wjmwcmkwpeqava80acphsu87vt5xlpqx6g7qh",
|
||||
consensus_pubkey: consensusPubkey,
|
||||
jailed: false,
|
||||
status: BondStatus.Bonded,
|
||||
tokens: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
@ -300,7 +301,7 @@ describe("StakingExtension", () => {
|
||||
max_rate: "0.200000000000000000",
|
||||
max_change_rate: "0.010000000000000000",
|
||||
},
|
||||
update_time: "2020-06-03T06:01:17.4747987Z",
|
||||
update_time: commissionUpdateTime,
|
||||
},
|
||||
min_self_delegation: "1",
|
||||
},
|
||||
@ -327,8 +328,7 @@ describe("StakingExtension", () => {
|
||||
result: [
|
||||
{
|
||||
operator_address: validatorAddress,
|
||||
consensus_pubkey:
|
||||
"cosmosvalconspub1zcjduepqau36ht2r742jh230pxlu4wjmwcmkwpeqava80acphsu87vt5xlpqx6g7qh",
|
||||
consensus_pubkey: consensusPubkey,
|
||||
jailed: false,
|
||||
status: BondStatus.Bonded,
|
||||
tokens: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
@ -348,7 +348,7 @@ describe("StakingExtension", () => {
|
||||
max_rate: "0.200000000000000000",
|
||||
max_change_rate: "0.010000000000000000",
|
||||
},
|
||||
update_time: "2020-06-03T06:01:17.4747987Z",
|
||||
update_time: commissionUpdateTime,
|
||||
},
|
||||
min_self_delegation: "1",
|
||||
},
|
||||
@ -366,8 +366,7 @@ describe("StakingExtension", () => {
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: {
|
||||
operator_address: validatorAddress,
|
||||
consensus_pubkey:
|
||||
"cosmosvalconspub1zcjduepqau36ht2r742jh230pxlu4wjmwcmkwpeqava80acphsu87vt5xlpqx6g7qh",
|
||||
consensus_pubkey: consensusPubkey,
|
||||
jailed: false,
|
||||
status: BondStatus.Bonded,
|
||||
tokens: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
@ -387,7 +386,7 @@ describe("StakingExtension", () => {
|
||||
max_rate: "0.200000000000000000",
|
||||
max_change_rate: "0.010000000000000000",
|
||||
},
|
||||
update_time: "2020-06-03T06:01:17.4747987Z",
|
||||
update_time: commissionUpdateTime,
|
||||
},
|
||||
min_self_delegation: "1",
|
||||
},
|
||||
@ -410,7 +409,7 @@ describe("StakingExtension", () => {
|
||||
balance: { denom: "ustake", amount: jasmine.stringMatching(nonNegativeIntegerMatcher) },
|
||||
},
|
||||
{
|
||||
delegator_address: "cosmos1gjvanqxc774u6ed9thj4gpn9gj5zus5u57dxvq",
|
||||
delegator_address: delegatorAddress,
|
||||
validator_address: validatorAddress,
|
||||
shares: "250000000.000000000000000000",
|
||||
balance: { denom: "ustake", amount: "250000000" },
|
@ -41,7 +41,8 @@ export const faucet = {
|
||||
address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
};
|
||||
|
||||
export const validatorAddress = "cosmosvaloper1gjvanqxc774u6ed9thj4gpn9gj5zus5u32enqn";
|
||||
export const validatorAddress = "cosmosvaloper1fa7hj49pf8uzc4m0lw5swjhhl5th2484gvnlpv";
|
||||
export const delegatorAddress = "cosmos1fa7hj49pf8uzc4m0lw5swjhhl5th2484dc82dl";
|
||||
|
||||
/** Unused account */
|
||||
export const unused = {
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user