Rename senderAddress -> signerAddress

This commit is contained in:
Simon Warta 2021-01-12 15:07:16 +01:00
parent 55d66be270
commit 4257988e02
8 changed files with 56 additions and 40 deletions

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

@ -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

@ -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

@ -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>>,