Merge pull request #613 from cosmos/signerAddress

Some API polishing
This commit is contained in:
mergify[bot] 2021-01-12 16:43:41 +00:00 committed by GitHub
commit a1ca6924a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 102 additions and 82 deletions

View File

@ -10,6 +10,8 @@
types as well as `isValidBuilder` and `parseWasmData` functions.
- @cosmjs/cosmwasm: Add `CosmWasmClient.getTx` method for searching by ID and
remove such functionality from `CosmWasmClient.searchTx`.
- @cosmjs/cosmwasm: Rename `SigningCosmWasmClient.senderAddress` to
`.signerAddress`.
- @cosmjs/cosmwasm-stargate: Add new package for CosmWasm Stargate support.
- @cosmjs/crypto: Change `Secp256k1Keypair` from tagged type to simple
interface.
@ -25,6 +27,8 @@
- @cosmjs/launchpad: Add `SigningCosmosClient.appendSignature` method creating
transactions with multiple signatures.
- @cosmjs/launchpad: Add support for undefined memo in `makeSignDoc`.
- @cosmjs/launchpad: Rename `SigningCosmosClient.senderAddress` to
`.signerAddress`.
- @cosmjs/launchpad-ledger: `LedgerSigner.sign` method renamed `signAmino`.
- @cosmjs/proto-signing: Add new package for handling transaction signing with
protobuf encoding.

View File

@ -24,7 +24,7 @@ export class Cw1CosmWasmClient extends SigningCosmWasmClient {
return super.getAccount(address || this.cw1ContractAddress);
}
public async canSend(msg: CosmosMsg, address = this.senderAddress): Promise<boolean> {
public async canSend(msg: CosmosMsg, address = this.signerAddress): Promise<boolean> {
const result = await this.queryContractSmart(this.cw1ContractAddress, {
can_send: {
sender: address,

View File

@ -61,7 +61,7 @@ export class Cw1SubkeyCosmWasmClient extends Cw1CosmWasmClient {
return admins;
}
public async isAdmin(address = this.senderAddress): Promise<boolean> {
public async isAdmin(address = this.signerAddress): Promise<boolean> {
const admins = await this.getAdmins();
return admins.includes(address);
}
@ -73,7 +73,7 @@ export class Cw1SubkeyCosmWasmClient extends Cw1CosmWasmClient {
return response.allowances;
}
public async getAllowance(address = this.senderAddress): Promise<Cw1SubkeyAllowanceInfo> {
public async getAllowance(address = this.signerAddress): Promise<Cw1SubkeyAllowanceInfo> {
return this.queryContractSmart(this.cw1ContractAddress, {
allowance: { spender: address },
});
@ -86,7 +86,7 @@ export class Cw1SubkeyCosmWasmClient extends Cw1CosmWasmClient {
return response.permissions;
}
public async getPermissions(address = this.senderAddress): Promise<Cw1SubkeyPermissions> {
public async getPermissions(address = this.signerAddress): Promise<Cw1SubkeyPermissions> {
return this.queryContractSmart(this.cw1ContractAddress, {
permissions: { spender: address },
});

View File

@ -149,7 +149,7 @@ export interface PrivateSigningCosmWasmClient {
}
export class SigningCosmWasmClient extends CosmWasmClient {
public readonly senderAddress: string;
public readonly signerAddress: string;
private readonly signer: OfflineSigner;
private readonly fees: CosmWasmFeeTable;
@ -161,7 +161,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
* for the lifetime of your application. When switching backends, a new instance must be created.
*
* @param apiUrl The URL of a Cosmos SDK light client daemon API (sometimes called REST server or REST API)
* @param senderAddress The address that will sign and send transactions using this instance
* @param signerAddress The address that will sign transactions using this instance. The `signer` must be able to sign with this address.
* @param signer An implementation of OfflineSigner which can provide signatures for transactions, potentially requiring user input.
* @param gasPrice The price paid per unit of gas
* @param gasLimits Custom overrides for gas limits related to specific transaction types
@ -169,25 +169,25 @@ export class SigningCosmWasmClient extends CosmWasmClient {
*/
public constructor(
apiUrl: string,
senderAddress: string,
signerAddress: string,
signer: OfflineSigner,
gasPrice: GasPrice = defaultGasPrice,
gasLimits: Partial<GasLimits<CosmWasmFeeTable>> = {},
broadcastMode = BroadcastMode.Block,
) {
super(apiUrl, broadcastMode);
this.anyValidAddress = senderAddress;
this.senderAddress = senderAddress;
this.anyValidAddress = signerAddress;
this.signerAddress = signerAddress;
this.signer = signer;
this.fees = buildFeeTable<CosmWasmFeeTable>(gasPrice, defaultGasLimits, gasLimits);
}
public async getSequence(address?: string): Promise<GetSequenceResult> {
return super.getSequence(address || this.senderAddress);
return super.getSequence(address || this.signerAddress);
}
public async getAccount(address?: string): Promise<Account | undefined> {
return super.getAccount(address || this.senderAddress);
return super.getAccount(address || this.signerAddress);
}
/** Uploads code and returns a receipt, including the code ID */
@ -199,7 +199,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
const storeCodeMsg: MsgStoreCode = {
type: "wasm/MsgStoreCode",
value: {
sender: this.senderAddress,
sender: this.signerAddress,
wasm_byte_code: toBase64(compressed),
source: source,
builder: builder,
@ -230,7 +230,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
const instantiateMsg: MsgInstantiateContract = {
type: "wasm/MsgInstantiateContract",
value: {
sender: this.senderAddress,
sender: this.signerAddress,
code_id: new Uint53(codeId).toString(),
label: label,
init_msg: initMsg,
@ -254,7 +254,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
const updateAdminMsg: MsgUpdateAdmin = {
type: "wasm/MsgUpdateAdmin",
value: {
sender: this.senderAddress,
sender: this.signerAddress,
contract: contractAddress,
new_admin: newAdmin,
},
@ -273,7 +273,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
const clearAdminMsg: MsgClearAdmin = {
type: "wasm/MsgClearAdmin",
value: {
sender: this.senderAddress,
sender: this.signerAddress,
contract: contractAddress,
},
};
@ -296,7 +296,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
const msg: MsgMigrateContract = {
type: "wasm/MsgMigrateContract",
value: {
sender: this.senderAddress,
sender: this.signerAddress,
contract: contractAddress,
code_id: new Uint53(codeId).toString(),
msg: migrateMsg,
@ -321,7 +321,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
const executeMsg: MsgExecuteContract = {
type: "wasm/MsgExecuteContract",
value: {
sender: this.senderAddress,
sender: this.signerAddress,
contract: contractAddress,
msg: handleMsg,
sent_funds: transferAmount || [],
@ -345,7 +345,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
const sendMsg: MsgSend = {
type: "cosmos-sdk/MsgSend",
value: {
from_address: this.senderAddress,
from_address: this.signerAddress,
to_address: recipientAddress,
amount: transferAmount,
},
@ -361,7 +361,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
const { accountNumber, sequence } = await this.getSequence();
const chainId = await this.getChainId();
const signDoc = makeSignDoc(msgs, fee, chainId, memo, accountNumber, sequence);
const { signed, signature } = await this.signer.signAmino(this.senderAddress, signDoc);
const { signed, signature } = await this.signer.signAmino(this.signerAddress, signDoc);
const signedTx = makeStdTx(signed, signature);
return this.broadcastTx(signedTx);
}

View File

@ -95,7 +95,7 @@ export interface PrivateSigningCosmWasmClient {
readonly fees: CosmWasmFeeTable;
}
export declare class SigningCosmWasmClient extends CosmWasmClient {
readonly senderAddress: string;
readonly signerAddress: string;
private readonly signer;
private readonly fees;
/**
@ -105,7 +105,7 @@ export declare class SigningCosmWasmClient extends CosmWasmClient {
* for the lifetime of your application. When switching backends, a new instance must be created.
*
* @param apiUrl The URL of a Cosmos SDK light client daemon API (sometimes called REST server or REST API)
* @param senderAddress The address that will sign and send transactions using this instance
* @param signerAddress The address that will sign transactions using this instance. The `signer` must be able to sign with this address.
* @param signer An implementation of OfflineSigner which can provide signatures for transactions, potentially requiring user input.
* @param gasPrice The price paid per unit of gas
* @param gasLimits Custom overrides for gas limits related to specific transaction types
@ -113,7 +113,7 @@ export declare class SigningCosmWasmClient extends CosmWasmClient {
*/
constructor(
apiUrl: string,
senderAddress: string,
signerAddress: string,
signer: OfflineSigner,
gasPrice?: GasPrice,
gasLimits?: Partial<GasLimits<CosmWasmFeeTable>>,

View File

@ -337,7 +337,7 @@ describe("CosmWasmClient", () => {
beforeAll(async () => {
if (wasmdEnabled()) {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, wasmd.prefix);
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, wallet);
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet);
const { codeId } = await client.upload(alice.address0, getHackatom().data);
const initMsg = { verifier: makeRandomAddress(), beneficiary: makeRandomAddress() };
const { contractAddress } = await client.instantiate(
@ -392,7 +392,7 @@ describe("CosmWasmClient", () => {
beforeAll(async () => {
if (wasmdEnabled()) {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, wasmd.prefix);
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, wallet);
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet);
const { codeId } = await client.upload(alice.address0, getHackatom().data);
const initMsg = { verifier: makeRandomAddress(), beneficiary: makeRandomAddress() };
const { contractAddress } = await client.instantiate(

View File

@ -62,7 +62,7 @@ async function uploadContract(
gas: "89000000",
};
const firstAddress = (await signer.getAccounts())[0].address;
const client = await SigningStargateClient.connectWithWallet(wasmd.endpoint, signer, { registry });
const client = await SigningStargateClient.connectWithSigner(wasmd.endpoint, signer, { registry });
return client.signAndBroadcast(firstAddress, [theMsg], fee, memo);
}
@ -94,7 +94,7 @@ async function instantiateContract(
};
const firstAddress = (await signer.getAccounts())[0].address;
const client = await SigningStargateClient.connectWithWallet(wasmd.endpoint, signer, { registry });
const client = await SigningStargateClient.connectWithSigner(wasmd.endpoint, signer, { registry });
return client.signAndBroadcast(firstAddress, [theMsg], fee, memo);
}
@ -119,7 +119,7 @@ async function executeContract(
};
const firstAddress = (await signer.getAccounts())[0].address;
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, signer, { registry });
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, signer, { registry });
return client.signAndBroadcast(firstAddress, [theMsg], fee, memo);
}

View File

@ -25,11 +25,11 @@ const { MsgDelegate } = codec.cosmos.staking.v1beta1;
const { Tx } = codec.cosmos.tx.v1beta1;
describe("SigningCosmWasmClient", () => {
describe("connectWithWallet", () => {
describe("connectWithSigner", () => {
it("can be constructed", async () => {
pendingWithoutWasmd();
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, wasmd.prefix);
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, wallet);
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet);
expect(client).toBeTruthy();
});
@ -37,7 +37,7 @@ describe("SigningCosmWasmClient", () => {
pendingWithoutWasmd();
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, wasmd.prefix);
const gasPrice = GasPrice.fromString("3.14utest");
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, wallet, { gasPrice });
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, { gasPrice });
const openedClient = (client as unknown) as PrivateSigningCosmWasmClient;
expect(openedClient.fees).toEqual({
upload: {
@ -73,7 +73,7 @@ describe("SigningCosmWasmClient", () => {
const gasLimits = {
send: 160000,
};
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, wallet, { gasLimits });
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, { gasLimits });
const openedClient = (client as unknown) as PrivateSigningCosmWasmClient;
expect(openedClient.fees).toEqual({
upload: {
@ -110,7 +110,7 @@ describe("SigningCosmWasmClient", () => {
const gasLimits = {
send: 160000,
};
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, wallet, {
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
gasPrice,
gasLimits,
});
@ -148,7 +148,7 @@ describe("SigningCosmWasmClient", () => {
it("works", async () => {
pendingWithoutWasmd();
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, wasmd.prefix);
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, wallet);
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet);
const wasm = getHackatom().data;
const {
codeId,
@ -167,7 +167,7 @@ describe("SigningCosmWasmClient", () => {
it("can set builder and source", async () => {
pendingWithoutWasmd();
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, wasmd.prefix);
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, wallet);
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet);
const hackatom = getHackatom();
const meta: UploadMeta = {
source: "https://crates.io/api/v1/crates/cw-nameservice/0.1.0/download",
@ -184,7 +184,7 @@ describe("SigningCosmWasmClient", () => {
it("works with transfer amount", async () => {
pendingWithoutWasmd();
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, wasmd.prefix);
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, wallet);
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet);
const { codeId } = await client.upload(alice.address0, getHackatom().data);
const transferAmount = [coin(1234, "ucosm"), coin(321, "ustake")];
const beneficiaryAddress = makeRandomAddress();
@ -211,7 +211,7 @@ describe("SigningCosmWasmClient", () => {
it("works with admin", async () => {
pendingWithoutWasmd();
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, wasmd.prefix);
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, wallet);
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet);
const { codeId } = await client.upload(alice.address0, getHackatom().data);
const beneficiaryAddress = makeRandomAddress();
const { contractAddress } = await client.instantiate(
@ -233,7 +233,7 @@ describe("SigningCosmWasmClient", () => {
it("can instantiate one code multiple times", async () => {
pendingWithoutWasmd();
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, wasmd.prefix);
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, wallet);
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet);
const { codeId } = await client.upload(alice.address0, getHackatom().data);
const contractAddress1 = await client.instantiate(
alice.address0,
@ -261,7 +261,7 @@ describe("SigningCosmWasmClient", () => {
it("can update an admin", async () => {
pendingWithoutWasmd();
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, wasmd.prefix);
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, wallet);
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet);
const { codeId } = await client.upload(alice.address0, getHackatom().data);
const beneficiaryAddress = makeRandomAddress();
const { contractAddress } = await client.instantiate(
@ -296,7 +296,7 @@ describe("SigningCosmWasmClient", () => {
it("can clear an admin", async () => {
pendingWithoutWasmd();
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, wasmd.prefix);
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, wallet);
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet);
const { codeId } = await client.upload(alice.address0, getHackatom().data);
const beneficiaryAddress = makeRandomAddress();
const { contractAddress } = await client.instantiate(
@ -331,7 +331,7 @@ describe("SigningCosmWasmClient", () => {
it("can can migrate from one code ID to another", async () => {
pendingWithoutWasmd();
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, wasmd.prefix);
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, wallet);
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet);
const { codeId: codeId1 } = await client.upload(alice.address0, getHackatom().data);
const { codeId: codeId2 } = await client.upload(alice.address0, getHackatom().data);
const beneficiaryAddress = makeRandomAddress();
@ -371,7 +371,7 @@ describe("SigningCosmWasmClient", () => {
it("works", async () => {
pendingWithoutWasmd();
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, wasmd.prefix);
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, wallet);
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet);
const { codeId } = await client.upload(alice.address0, getHackatom().data);
// instantiate
const transferAmount = [coin(233444, "ucosm"), coin(5454, "ustake")];
@ -414,7 +414,7 @@ describe("SigningCosmWasmClient", () => {
it("works", async () => {
pendingWithoutWasmd();
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, wasmd.prefix);
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, wallet);
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet);
const transferAmount = coins(7890, "ucosm");
const beneficiaryAddress = makeRandomAddress();
@ -445,7 +445,7 @@ describe("SigningCosmWasmClient", () => {
const registry = new Registry();
registry.register(msgDelegateTypeUrl, MsgDelegate);
const options = { registry: registry };
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, wallet, options);
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options);
const msg = MsgDelegate.create({
delegatorAddress: alice.address0,
@ -476,7 +476,7 @@ describe("SigningCosmWasmClient", () => {
const registry = new Registry();
registry.register(msgDelegateTypeUrl, MsgDelegate);
const options = { registry: registry };
const client = await SigningCosmWasmClient.connectWithWallet(wasmd.endpoint, wallet, options);
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options);
const msg = MsgDelegate.create({
delegatorAddress: alice.address0,

View File

@ -106,7 +106,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
private readonly registry: Registry;
private readonly signer: OfflineDirectSigner;
public static async connectWithWallet(
public static async connectWithSigner(
endpoint: string,
signer: OfflineDirectSigner,
options: SigningCosmWasmClientOptions = {},
@ -314,20 +314,28 @@ export class SigningCosmWasmClient extends CosmWasmClient {
return this.signAndBroadcast(senderAddress, [sendMsg], this.fees.send, memo);
}
/**
* Creates a transaction with the given messages, fee and memo. Then signs and broadcasts the transaction.
*
* @param signerAddress The address that will sign transactions using this instance. The signer must be able to sign with this address.
* @param messages
* @param fee
* @param memo
*/
public async signAndBroadcast(
address: string,
signerAddress: string,
messages: readonly EncodeObject[],
fee: StdFee,
memo = "",
): Promise<BroadcastTxResponse> {
const accountFromSigner = (await this.signer.getAccounts()).find(
(account: AccountData) => account.address === address,
(account: AccountData) => account.address === signerAddress,
);
if (!accountFromSigner) {
throw new Error("Failed to retrieve account from signer");
}
const pubkey = encodeSecp256k1Pubkey(accountFromSigner.pubkey);
const accountFromChain = await this.getAccount(address);
const accountFromChain = await this.getAccount(signerAddress);
if (!accountFromChain) {
throw new Error("Account not found");
}
@ -349,7 +357,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
const authInfoBytes = makeAuthInfoBytes([pubkeyAny], fee.amount, gasLimit, sequence);
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
const { signature, signed } = await this.signer.signDirect(address, signDoc);
const { signature, signed } = await this.signer.signDirect(signerAddress, signDoc);
const txRaw = TxRaw.create({
bodyBytes: signed.bodyBytes,
authInfoBytes: signed.authInfoBytes,

View File

@ -25,7 +25,7 @@ export declare class SigningCosmWasmClient extends CosmWasmClient {
private readonly fees;
private readonly registry;
private readonly signer;
static connectWithWallet(
static connectWithSigner(
endpoint: string,
signer: OfflineDirectSigner,
options?: SigningCosmWasmClientOptions,
@ -72,8 +72,16 @@ export declare class SigningCosmWasmClient extends CosmWasmClient {
transferAmount: readonly Coin[],
memo?: string,
): Promise<BroadcastTxResponse>;
/**
* Creates a transaction with the given messages, fee and memo. Then signs and broadcasts the transaction.
*
* @param signerAddress The address that will sign transactions using this instance. The signer must be able to sign with this address.
* @param messages
* @param fee
* @param memo
*/
signAndBroadcast(
address: string,
signerAddress: string,
messages: readonly EncodeObject[],
fee: StdFee,
memo?: string,

View File

@ -43,7 +43,7 @@ export async function createClients(
> => [
senderAddress,
isOfflineDirectSigner(wallet)
? await SigningStargateClient.connectWithWallet(apiUrl, wallet, {
? await SigningStargateClient.connectWithSigner(apiUrl, wallet, {
gasLimits: constants.gasLimits,
gasPrice: constants.gasPrice,
})

View File

@ -27,7 +27,7 @@ export interface PrivateSigningCosmosClient {
}
export class SigningCosmosClient extends CosmosClient {
public readonly senderAddress: string;
public readonly signerAddress: string;
private readonly signer: OfflineSigner;
private readonly fees: CosmosFeeTable;
@ -39,7 +39,7 @@ export class SigningCosmosClient extends CosmosClient {
* for the lifetime of your application. When switching backends, a new instance must be created.
*
* @param apiUrl The URL of a Cosmos SDK light client daemon API (sometimes called REST server or REST API)
* @param senderAddress The address that will sign and send transactions using this instance
* @param signerAddress The address that will sign transactions using this instance. The `signer` must be able to sign with this address.
* @param signer An implementation of OfflineSigner which can provide signatures for transactions, potentially requiring user input.
* @param gasPrice The price paid per unit of gas
* @param gasLimits Custom overrides for gas limits related to specific transaction types
@ -47,25 +47,25 @@ export class SigningCosmosClient extends CosmosClient {
*/
public constructor(
apiUrl: string,
senderAddress: string,
signerAddress: string,
signer: OfflineSigner,
gasPrice: GasPrice = defaultGasPrice,
gasLimits: Partial<GasLimits<CosmosFeeTable>> = {},
broadcastMode = BroadcastMode.Block,
) {
super(apiUrl, broadcastMode);
this.anyValidAddress = senderAddress;
this.senderAddress = senderAddress;
this.anyValidAddress = signerAddress;
this.signerAddress = signerAddress;
this.signer = signer;
this.fees = buildFeeTable<CosmosFeeTable>(gasPrice, defaultGasLimits, gasLimits);
}
public async getSequence(address?: string): Promise<GetSequenceResult> {
return super.getSequence(address || this.senderAddress);
return super.getSequence(address || this.signerAddress);
}
public async getAccount(address?: string): Promise<Account | undefined> {
return super.getAccount(address || this.senderAddress);
return super.getAccount(address || this.signerAddress);
}
public async sendTokens(
@ -76,7 +76,7 @@ export class SigningCosmosClient extends CosmosClient {
const sendMsg: MsgSend = {
type: "cosmos-sdk/MsgSend",
value: {
from_address: this.senderAddress,
from_address: this.signerAddress,
to_address: recipientAddress,
amount: transferAmount,
},
@ -101,7 +101,7 @@ export class SigningCosmosClient extends CosmosClient {
const { accountNumber, sequence } = await this.getSequence();
const chainId = await this.getChainId();
const signDoc = makeSignDoc(msgs, fee, chainId, memo, accountNumber, sequence);
const { signed, signature } = await this.signer.signAmino(this.senderAddress, signDoc);
const { signed, signature } = await this.signer.signAmino(this.signerAddress, signDoc);
return makeStdTx(signed, signature);
}
@ -115,7 +115,7 @@ export class SigningCosmosClient extends CosmosClient {
const chainId = await this.getChainId();
const signDoc = makeSignDoc(msgs, fee, chainId, memo, accountNumber, sequence);
const { signed, signature: additionalSignature } = await this.signer.signAmino(
this.senderAddress,
this.signerAddress,
signDoc,
);
if (!equals(signDoc, signed)) {

View File

@ -17,7 +17,7 @@ export interface PrivateSigningCosmosClient {
readonly fees: CosmosFeeTable;
}
export declare class SigningCosmosClient extends CosmosClient {
readonly senderAddress: string;
readonly signerAddress: string;
private readonly signer;
private readonly fees;
/**
@ -27,7 +27,7 @@ export declare class SigningCosmosClient extends CosmosClient {
* for the lifetime of your application. When switching backends, a new instance must be created.
*
* @param apiUrl The URL of a Cosmos SDK light client daemon API (sometimes called REST server or REST API)
* @param senderAddress The address that will sign and send transactions using this instance
* @param signerAddress The address that will sign transactions using this instance. The `signer` must be able to sign with this address.
* @param signer An implementation of OfflineSigner which can provide signatures for transactions, potentially requiring user input.
* @param gasPrice The price paid per unit of gas
* @param gasLimits Custom overrides for gas limits related to specific transaction types
@ -35,7 +35,7 @@ export declare class SigningCosmosClient extends CosmosClient {
*/
constructor(
apiUrl: string,
senderAddress: string,
signerAddress: string,
signer: OfflineSigner,
gasPrice?: GasPrice,
gasLimits?: Partial<GasLimits<CosmosFeeTable>>,

View File

@ -26,7 +26,7 @@ describe("SigningStargateClient", () => {
it("can be constructed with default fees", async () => {
pendingWithoutSimapp();
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic);
const client = await SigningStargateClient.connectWithWallet(simapp.tendermintUrl, wallet);
const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet);
const openedClient = (client as unknown) as PrivateSigningStargateClient;
expect(openedClient.fees).toEqual({
send: {
@ -47,7 +47,7 @@ describe("SigningStargateClient", () => {
const registry = new Registry();
registry.register("/custom.MsgCustom", MsgSend);
const options = { registry: registry };
const client = await SigningStargateClient.connectWithWallet(simapp.tendermintUrl, wallet, options);
const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet, options);
const openedClient = (client as unknown) as PrivateSigningStargateClient;
expect(openedClient.registry.lookupType("/custom.MsgCustom")).toEqual(MsgSend);
});
@ -57,7 +57,7 @@ describe("SigningStargateClient", () => {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic);
const gasPrice = GasPrice.fromString("3.14utest");
const options = { gasPrice: gasPrice };
const client = await SigningStargateClient.connectWithWallet(simapp.tendermintUrl, wallet, options);
const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet, options);
const openedClient = (client as unknown) as PrivateSigningStargateClient;
expect(openedClient.fees).toEqual({
send: {
@ -79,7 +79,7 @@ describe("SigningStargateClient", () => {
send: 160000,
};
const options = { gasLimits: gasLimits };
const client = await SigningStargateClient.connectWithWallet(simapp.tendermintUrl, wallet, options);
const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet, options);
const openedClient = (client as unknown) as PrivateSigningStargateClient;
expect(openedClient.fees).toEqual({
send: {
@ -102,7 +102,7 @@ describe("SigningStargateClient", () => {
send: 160000,
};
const options = { gasPrice: gasPrice, gasLimits: gasLimits };
const client = await SigningStargateClient.connectWithWallet(simapp.tendermintUrl, wallet, options);
const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet, options);
const openedClient = (client as unknown) as PrivateSigningStargateClient;
expect(openedClient.fees).toEqual({
send: {
@ -122,7 +122,7 @@ describe("SigningStargateClient", () => {
it("works", async () => {
pendingWithoutSimapp();
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic);
const client = await SigningStargateClient.connectWithWallet(simapp.tendermintUrl, wallet);
const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet);
const transferAmount = coins(7890, "ucosm");
const beneficiaryAddress = makeRandomAddress();
@ -153,7 +153,7 @@ describe("SigningStargateClient", () => {
const registry = new Registry();
registry.register(msgDelegateTypeUrl, MsgDelegate);
const options = { registry: registry };
const client = await SigningStargateClient.connectWithWallet(simapp.tendermintUrl, wallet, options);
const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet, options);
const msg = MsgDelegate.create({
delegatorAddress: faucet.address0,
@ -180,7 +180,7 @@ describe("SigningStargateClient", () => {
const registry = new Registry();
registry.register(msgDelegateTypeUrl, MsgDelegate);
const options = { registry: registry };
const client = await SigningStargateClient.connectWithWallet(simapp.tendermintUrl, wallet, options);
const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet, options);
const msg = MsgDelegate.create({
delegatorAddress: faucet.address0,
@ -233,7 +233,7 @@ describe("SigningStargateClient", () => {
pendingWithoutSimapp();
const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic);
const options = { registry: registry };
const client = await SigningStargateClient.connectWithWallet(simapp.tendermintUrl, wallet, options);
const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet, options);
const msg = {
delegator_address: faucet.address0,
@ -257,7 +257,7 @@ describe("SigningStargateClient", () => {
pendingWithoutSimapp();
const wallet = await ModifyingSecp256k1HdWallet.fromMnemonic(faucet.mnemonic);
const options = { registry: registry };
const client = await SigningStargateClient.connectWithWallet(simapp.tendermintUrl, wallet, options);
const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet, options);
const msg = {
delegator_address: faucet.address0,

View File

@ -50,7 +50,7 @@ export class SigningStargateClient extends StargateClient {
private readonly signer: OfflineSigner;
private readonly aminoTypes = new AminoTypes();
public static async connectWithWallet(
public static async connectWithSigner(
endpoint: string,
signer: OfflineSigner,
options: SigningStargateClientOptions = {},

View File

@ -16,7 +16,7 @@ export declare class SigningStargateClient extends StargateClient {
private readonly registry;
private readonly signer;
private readonly aminoTypes;
static connectWithWallet(
static connectWithSigner(
endpoint: string,
signer: OfflineSigner,
options?: SigningStargateClientOptions,

View File

@ -22,7 +22,7 @@ const codeMeta = {
async function main() {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, "wasm");
const client = await SigningCosmWasmClient.connectWithWallet(endpoint, wallet);
const client = await SigningCosmWasmClient.connectWithSigner(endpoint, wallet);
const wasm = fs.readFileSync(__dirname + "/contracts/cw1_subkeys.wasm");
const uploadReceipt = await client.upload(alice.address0, wasm, codeMeta, "Upload CW1 subkeys contract");

View File

@ -64,7 +64,7 @@ const initData = [
async function main() {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, "wasm");
const client = await SigningCosmWasmClient.connectWithWallet(endpoint, wallet);
const client = await SigningCosmWasmClient.connectWithSigner(endpoint, wallet);
const wasm = fs.readFileSync(__dirname + "/contracts/cw3_fixed_multisig.wasm");
const uploadReceipt = await client.upload(

View File

@ -135,7 +135,7 @@ const initDataJade = {
async function main() {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, "wasm");
const client = await SigningCosmWasmClient.connectWithWallet(endpoint, wallet);
const client = await SigningCosmWasmClient.connectWithSigner(endpoint, wallet);
const wasm = fs.readFileSync(__dirname + "/contracts/cw_erc20.wasm");
const uploadReceipt = await client.upload(alice.address0, wasm, codeMeta, "Upload ERC20 contract");

View File

@ -49,7 +49,7 @@ const inits = [
async function main() {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, "wasm");
const client = await SigningCosmWasmClient.connectWithWallet(endpoint, wallet);
const client = await SigningCosmWasmClient.connectWithSigner(endpoint, wallet);
const wasm = fs.readFileSync(__dirname + "/contracts/hackatom.wasm");
const uploadReceipt = await client.upload(alice.address0, wasm, codeMeta, "Upload hackatom contract");

View File

@ -17,7 +17,7 @@ const faucet = {
async function main() {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic, undefined, prefix);
const client = await SigningStargateClient.connectWithWallet(rpcUrl, wallet);
const client = await SigningStargateClient.connectWithSigner(rpcUrl, wallet);
const recipient = Bech32.encode(prefix, Random.getBytes(20));
const amount = coins(226644, "ucosm");
const memo = "Ensure chain has my pubkey";