Skip to content

Commit

Permalink
feat: MsgSettle
Browse files Browse the repository at this point in the history
  • Loading branch information
rrr523 committed Sep 11, 2023
1 parent 4ef30b7 commit 6b52f3f
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 3 deletions.
48 changes: 48 additions & 0 deletions examples/nextjs/src/components/vg/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { client, selectSp } from '@/client';
import { useAccount } from 'wagmi';

export const VirtualGroup = () => {
const { address, connector } = useAccount();

return (
<div>
<h3>Virtual Group</h3>

<button
onClick={async () => {
if (!address) return;

const sp = await selectSp();

const tx = await client.virtualGroup.settle(address, {
globalVirtualGroupFamilyId: 1,
globalVirtualGroupIds: [2],
storageProvider: sp.primarySpAddress,
});

const simuluateInfo = await tx.simulate({
denom: 'BNB',
});

console.log('simuluateInfo', simuluateInfo);
const res = await tx.broadcast({
denom: 'BNB',
gasLimit: Number(210000),
gasPrice: '5000000000',
payer: address,
granter: '',
});

console.log('res', res);

if (res.code === 0) {
alert('success');
}
}}
>
settle
</button>
<br />
</div>
);
};
3 changes: 3 additions & 0 deletions examples/nextjs/src/pages/tx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { PaymentComponent } from '@/components/payment';
import { Validator } from '@/components/validator';
import { Proposal } from '@/components/proposal';
import { Distribution } from '@/components/distribution';
import { VirtualGroup } from '@/components/vg';

export default function Tx() {
const isMounted = useIsMounted();
Expand Down Expand Up @@ -56,6 +57,8 @@ export default function Tx() {
<hr style={{ margin: '10px 0' }} />
<Distribution />
<hr style={{ margin: '10px 0' }} />
<VirtualGroup />
<hr style={{ margin: '10px 0' }} />
<MultiMsg />
</>
)}
Expand Down
1 change: 0 additions & 1 deletion packages/chain-sdk/src/api/distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export interface IDistribution {
@injectable()
export class Distribution implements IDistribution {
constructor(@inject(delay(() => TxClient)) private txClient: TxClient) {}
private queryClient: RpcQueryClient = container.resolve(RpcQueryClient);

public async setWithdrawAddress(msg: MsgSetWithdrawAddress) {
return await this.txClient.tx(
Expand Down
19 changes: 18 additions & 1 deletion packages/chain-sdk/src/api/virtualGroup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { TxClient } from '@/clients/txClient';
import { MsgSettleSDKTypeEIP712 } from '@/messages/greenfield/virtualgroup/MsgSettle';
import {
QueryGlobalVirtualGroupByFamilyIDRequest,
QueryGlobalVirtualGroupByFamilyIDResponse,
Expand All @@ -9,7 +11,9 @@ import {
QueryGlobalVirtualGroupResponse,
QueryParamsResponse,
} from '@bnb-chain/greenfield-cosmos-types/greenfield/virtualgroup/query';
import { container, injectable } from 'tsyringe';
import { MsgSettle } from '@bnb-chain/greenfield-cosmos-types/greenfield/virtualgroup/tx';
import { container, delay, inject, injectable } from 'tsyringe';
import { MsgSettleTypeUrl, TxResponse } from '..';
import { RpcQueryClient } from '../clients/queryclient';

export interface IVirtualGroup {
Expand All @@ -30,10 +34,13 @@ export interface IVirtualGroup {
getGlobalVirtualGroupFamily(
request: QueryGlobalVirtualGroupFamilyRequest,
): Promise<QueryGlobalVirtualGroupFamilyResponse>;

settle(address: string, msg: MsgSettle): Promise<TxResponse>;
}

@injectable()
export class VirtualGroup implements IVirtualGroup {
constructor(@inject(delay(() => TxClient)) private txClient: TxClient) {}
private queryClient = container.resolve(RpcQueryClient);

public async params() {
Expand All @@ -60,4 +67,14 @@ export class VirtualGroup implements IVirtualGroup {
const rpc = await this.queryClient.getVirtualGroupClient();
return await rpc.GlobalVirtualGroupFamily(request);
}

public async settle(address: string, msg: MsgSettle) {
return await this.txClient.tx(
MsgSettleTypeUrl,
address,
MsgSettleSDKTypeEIP712,
MsgSettle.toSDK(msg),
MsgSettle.encode(msg).finish(),
);
}
}
2 changes: 1 addition & 1 deletion packages/chain-sdk/src/clients/txClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { makeAuthInfoBytes } from '@cosmjs/proto-signing';
import { DeliverTxResponse, StargateClient } from '@cosmjs/stargate';
import { Tendermint37Client } from '@cosmjs/tendermint-rpc';
import { arrayify } from '@ethersproject/bytes';
import { arrayify, hexlify } from '@ethersproject/bytes';
import { signTypedData, SignTypedDataVersion } from '@metamask/eth-sig-util';
import { container, inject, injectable } from 'tsyringe';
import {
Expand Down
1 change: 1 addition & 0 deletions packages/chain-sdk/src/constants/typeUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ export const MsgSetWithdrawAddressTypeUrl = '/cosmos.distribution.v1beta1.MsgSet
export const MsgWithdrawValidatorCommissionTypeUrl =
'/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission';
export const MsgFundCommunityPoolTypeUrl = '/cosmos.distribution.v1beta1.MsgFundCommunityPool';
export const MsgSettleTypeUrl = '/greenfield.virtualgroup.MsgSettle';
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export const MsgSettleSDKTypeEIP712 = {
Msg1: [
{
name: 'global_virtual_group_family_id',
type: 'uint32',
},
{
name: 'global_virtual_group_ids',
type: 'uint32[]',
},
{
name: 'storage_provider',
type: 'string',
},
{
name: 'type',
type: 'string',
},
],
};

0 comments on commit 6b52f3f

Please sign in to comment.