Skip to content

Commit

Permalink
feat: update message for apps cosmos
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhnv2303 committed Oct 13, 2022
1 parent e29bd8b commit e684a14
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 14 deletions.
16 changes: 10 additions & 6 deletions src/lib/cosm/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { OfflineSigner } from '@cosmjs/proto-signing';
import {
SigningStargateClientOptions
} from '@cosmjs/stargate/build/signingstargateclient';
import { SigningStargateClientOptions } from '@cosmjs/stargate/build/signingstargateclient';
import Cosmos from '../cosmos';
import { provider } from '../providers';
import { Utils } from '../utils';
Expand Down Expand Up @@ -35,12 +33,18 @@ export default class Cosm {
this.cosmos = new Cosmos(provider);
this.wasm = new Wasm(provider);
this.utils = new Utils();

}

async setSigner(offlineSigner: OfflineSigner, options?: SigningStargateClientOptions) {
async setSigner(
offlineSigner: OfflineSigner,
options?: SigningStargateClientOptions
) {
this.offlineSinger = offlineSigner;
this._wallet = await Wallet.connectWithSigner(this._provider.rpcUrl, offlineSigner, options);
this._wallet = await Wallet.connectWithSigner(
this._provider.rpcUrl,
offlineSigner,
options
);
}

async setWallet(wallet: Wallet) {
Expand Down
19 changes: 18 additions & 1 deletion src/lib/cosmos/app.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import { provider } from '../providers';
import {
createProtobufRpcStateClient,
ProtobufRpcStateClient,
ProtobufRpcStateClient
} from '../queryclient/utils';
import { Wallet } from '../wallet';

export class App {
set wallet(value: Wallet) {
this._wallet = value;
}

get wallet(): Wallet {
if (!this._wallet) {
throw 'Must set wallet first';
}
return this._wallet;
}

public message;
public protobuf;
public query;
Expand All @@ -13,6 +25,7 @@ export class App {

private provider: provider;
private readonly rpc: ProtobufRpcStateClient;
private _wallet: Wallet;

constructor(provider: provider) {
this.provider = provider;
Expand All @@ -34,4 +47,8 @@ export class App {
setMessage(Message: any) {
this.message = Message(this.rpc);
}

setWallet(wallet: Wallet) {
this._wallet = wallet;
}
}
3 changes: 3 additions & 0 deletions src/lib/cosmos/authz.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import * as Protobuf from 'cosmjs-types/cosmos/authz/v1beta1/authz';
import { QueryClientImpl } from 'cosmjs-types/cosmos/authz/v1beta1/query';
import { MsgClientImpl } from 'cosmjs-types/cosmos/authz/v1beta1/tx';

import { provider } from '../providers';

import { App } from './app';

export class Authz extends App {
public declare query: QueryClientImpl;
public declare message: MsgClientImpl;
public protobuf = Protobuf;

constructor(provider: provider) {
super(provider);
this.setQueryClient(QueryClientImpl);
this.setMessage(MsgClientImpl)
}
}
3 changes: 3 additions & 0 deletions src/lib/cosmos/bank.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import * as Protobuf from 'cosmjs-types/cosmos/bank/v1beta1/bank';
import { QueryClientImpl } from 'cosmjs-types/cosmos/bank/v1beta1/query';
import { MsgClientImpl } from 'cosmjs-types/cosmos/bank/v1beta1/tx';

import { provider } from '../providers';

import { App } from './app';

export class Bank extends App {
public declare query: QueryClientImpl;
public declare message: MsgClientImpl;
public protobuf = Protobuf;

constructor(provider: provider) {
super(provider);
this.setQueryClient(QueryClientImpl);
this.setMessage(MsgClientImpl);
}
}
4 changes: 4 additions & 0 deletions src/lib/cosmos/crisis.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { MsgClientImpl } from 'cosmjs-types/cosmos/crisis/v1beta1/tx';
import { provider } from '../providers';

import { App } from './app';

export class Crisis extends App {
public declare message: MsgClientImpl;

constructor(provider: provider) {
super(provider);
this.setMessage(MsgClientImpl);
}
}
9 changes: 7 additions & 2 deletions src/lib/cosmos/distribution.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as Protobuf from 'cosmjs-types/cosmos/distribution/v1beta1/distribution';
import { QueryClientImpl } from 'cosmjs-types/cosmos/distribution/v1beta1/query';
import * as Protobuf
from 'cosmjs-types/cosmos/distribution/v1beta1/distribution';
import {
QueryClientImpl
} from 'cosmjs-types/cosmos/distribution/v1beta1/query';
import { MsgClientImpl } from 'cosmjs-types/cosmos/distribution/v1beta1/tx';

import { provider } from '../providers';

Expand All @@ -12,5 +16,6 @@ export class Distribution extends App {
constructor(provider: provider) {
super(provider);
this.setQueryClient(QueryClientImpl);
this.setMessage(MsgClientImpl);
}
}
3 changes: 3 additions & 0 deletions src/lib/cosmos/evidence.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import * as Protobuf from 'cosmjs-types/cosmos/evidence/v1beta1/evidence';
import { QueryClientImpl } from 'cosmjs-types/cosmos/evidence/v1beta1/query';
import { MsgClientImpl } from 'cosmjs-types/cosmos/evidence/v1beta1/tx';

import { provider } from '../providers';

import { App } from './app';

export class Evidence extends App {
public declare query: QueryClientImpl;
public declare message: MsgClientImpl;
public protobuf = Protobuf;

constructor(provider: provider) {
super(provider);
this.setQueryClient(QueryClientImpl);
this.setMessage(MsgClientImpl);
}
}
2 changes: 2 additions & 0 deletions src/lib/cosmos/feegrant.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Protobuf from 'cosmjs-types/cosmos/feegrant/v1beta1/feegrant';
import { QueryClientImpl } from 'cosmjs-types/cosmos/feegrant/v1beta1/query';
import { MsgClientImpl } from 'cosmjs-types/cosmos/feegrant/v1beta1/tx';

import { provider } from '../providers';

Expand All @@ -12,5 +13,6 @@ export class FeeGrant extends App {
constructor(provider: provider) {
super(provider);
this.setQueryClient(QueryClientImpl);
this.setMessage(MsgClientImpl);
}
}
3 changes: 3 additions & 0 deletions src/lib/cosmos/gov.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import * as Protobuf from 'cosmjs-types/cosmos/gov/v1beta1/gov';
import { QueryClientImpl } from 'cosmjs-types/cosmos/gov/v1beta1/query';
import { MsgClientImpl } from 'cosmjs-types/cosmos/gov/v1beta1/tx';

import { provider } from '../providers';

import { App } from './app';

export class Gov extends App {
public declare query: QueryClientImpl;
public declare message: MsgClientImpl;
public protobuf = Protobuf;

constructor(provider: provider) {
super(provider);
this.setQueryClient(QueryClientImpl);
this.setMessage(MsgClientImpl);
}
}
39 changes: 38 additions & 1 deletion src/lib/cosmos/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { version } from '../cosm/version';
import { provider } from '../providers';
import { Wallet } from '../wallet';
import { App } from './app';
import { Auth } from './auth';
import { Authz } from './authz';
Expand All @@ -22,9 +23,19 @@ import { Upgrade } from './upgrade';
import { Vesting } from './vesting';

export default class Cosmos {
set wallet(value: Wallet) {
this._wallet = value;
}

get wallet(): Wallet {
if (!this._wallet) {
throw 'Must set wallet first';
}
return this._wallet;
}

private _provider: provider;
public version: string;

public app: App;
public auth: Auth;
public authz: Authz;
Expand All @@ -45,9 +56,11 @@ export default class Cosmos {
public tx: Tx;
public upgrade: Upgrade;
public vesting: Vesting;
private _wallet: Wallet;

constructor(provider: provider) {
this._provider = provider;

this.app = new App(provider);
this.auth = new Auth(provider);
this.authz = new Authz(provider);
Expand All @@ -70,4 +83,28 @@ export default class Cosmos {
this.vesting = new Vesting(provider);
this.version = version;
}

setWallet(wallet: Wallet) {
this._wallet = wallet;
this.app.wallet = wallet;
this.auth.wallet = wallet;
this.authz.wallet = wallet;
this.bank.wallet = wallet;
this.base.wallet = wallet;
this.capability.wallet = wallet;
this.crisis.wallet = wallet;
this.crypto.wallet = wallet;
this.distribution.wallet = wallet;
this.evidence.wallet = wallet;
this.feegrant.wallet = wallet;
this.genutil.wallet = wallet;
this.gov.wallet = wallet;
this.mint.wallet = wallet;
this.params.wallet = wallet;
this.slashing.wallet = wallet;
this.staking.wallet = wallet;
this.tx.wallet = wallet;
this.upgrade.wallet = wallet;
this.vesting.wallet = wallet;
}
}
5 changes: 4 additions & 1 deletion src/lib/cosmos/slashing.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import * as Protobuf from 'cosmjs-types/cosmos/slashing/v1beta1/slashing';
import { QueryClientImpl } from 'cosmjs-types/cosmos/slashing/v1beta1/query';
import * as Protobuf from 'cosmjs-types/cosmos/slashing/v1beta1/slashing';
import { MsgClientImpl } from 'cosmjs-types/cosmos/slashing/v1beta1/tx';

import { provider } from '../providers';

import { App } from './app';

export class Slashing extends App {
public declare query: QueryClientImpl;
public declare message: MsgClientImpl;
public protobuf = Protobuf;

constructor(provider: provider) {
super(provider);
this.setQueryClient(QueryClientImpl);
this.setMessage(MsgClientImpl);
}
}
3 changes: 3 additions & 0 deletions src/lib/cosmos/staking.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { QueryClientImpl } from 'cosmjs-types/cosmos/staking/v1beta1/query';
import * as StakingProtobuf from 'cosmjs-types/cosmos/staking/v1beta1/staking';
import { BondStatus } from 'cosmjs-types/cosmos/staking/v1beta1/staking';
import { MsgClientImpl } from 'cosmjs-types/cosmos/staking/v1beta1/tx';

import { provider } from '../providers';

Expand All @@ -10,10 +11,12 @@ export const ValidatorBondStatus = BondStatus;

export class Staking extends App {
public declare query: QueryClientImpl;
public declare message: MsgClientImpl;
public protobuf = StakingProtobuf;

constructor(provider: provider) {
super(provider);
this.setQueryClient(QueryClientImpl);
this.setMessage(MsgClientImpl);
}
}
3 changes: 3 additions & 0 deletions src/lib/cosmos/vesting.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MsgClientImpl } from 'cosmjs-types/cosmos/vesting/v1beta1/tx';
import * as Protobuf from 'cosmjs-types/cosmos/vesting/v1beta1/vesting';

import { provider } from '../providers';
Expand All @@ -6,8 +7,10 @@ import { App } from './app';

export class Vesting extends App {
public protobuf = Protobuf;
public declare message: MsgClientImpl;

constructor(provider: provider) {
super(provider);
this.setMessage(MsgClientImpl);
}
}
4 changes: 1 addition & 3 deletions src/lib/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { OfflineSigner } from '@cosmjs/proto-signing';
import { AccountData } from '@cosmjs/proto-signing/build/signer';
import {
SigningStargateClient,
SigningStargateClientOptions
SigningStargateClientOptions,
} from '@cosmjs/stargate';
import { Tendermint34Client } from '@cosmjs/tendermint-rpc';
import { HttpEndpoint } from '@cosmjs/tendermint-rpc/build/rpcclients';
Expand All @@ -12,7 +12,6 @@ import { TendermintBatchClient } from '../tendermint-rpc/tendermintbatchclient';
export default OfflineSigner;

export class Wallet extends SigningStargateClient {

_signer: OfflineSigner;
_tendermintBatchClient: TendermintBatchClient;
_tendermintClient: Tendermint34Client;
Expand Down Expand Up @@ -55,5 +54,4 @@ export class Wallet extends SigningStargateClient {
const listAddress = await this.getAddresses();
return listAddress[0];
}

}

0 comments on commit e684a14

Please sign in to comment.