Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support core@v2.1.0 #320

Merged
merged 4 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
},
"dependencies": {
"@terra-money/legacy.proto": "npm:@terra-money/terra.proto@^0.1.7",
"@terra-money/terra.proto": "~2.0.0",
"@terra-money/terra.proto": "^2.1.0",
"axios": "^0.26.1",
"bech32": "^2.0.0",
"bip32": "^2.0.6",
Expand Down
13 changes: 13 additions & 0 deletions src/client/lcd/api/FeeGrantAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,17 @@ describe('FeeGrantAPI', () => {
).rejects.toThrow();
});
});

it('allowancesByGranter', async () => {
const res = await feeGrant.allowancesByGranter(
'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v'
);
expect(res.allowances[0]).toMatchObject({
granter: expect.any(String),
grantee: expect.any(String),
});
const allowanceData = res.allowances[0].allowance.toData();
expect(allowanceData['@type']).toMatch(/cosmos.feegrant.v1beta1/g);
expect(res.pagination).not.toBeUndefined();
});
});
34 changes: 33 additions & 1 deletion src/client/lcd/api/FeeGrantAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Pagination, PaginationOptions } from '../APIRequester';
import { LCDClient } from '../LCDClient';

export class FeeGrantAPI extends BaseAPI {

constructor(public lcd: LCDClient) {
super(lcd.apiRequester);
}
Expand Down Expand Up @@ -54,4 +53,37 @@ export class FeeGrantAPI extends BaseAPI {
}>(`/cosmos/feegrant/v1beta1/allowance/${granter}/${grantee}`)
.then(d => Allowance.fromData(d.allowance.allowance));
}

public async allowancesByGranter(
granter: AccAddress,
params: Partial<PaginationOptions> = {}
): Promise<{
allowances: {
granter: AccAddress;
grantee: AccAddress;
allowance: Allowance;
}[];
pagination: Pagination;
}> {
if (this.lcd.config.isClassic) {
throw new Error('Not supported for the network');
}
return this.c
.get<{
allowances: {
granter: AccAddress;
grantee: AccAddress;
allowance: Allowance.Data;
}[];
pagination: Pagination;
}>(`/cosmos/feegrant/v1beta1/issued/${granter}`, params)
.then(d => ({
allowances: d.allowances.map(allowance => ({
granter: allowance.granter,
grantee: allowance.grantee,
allowance: Allowance.fromData(allowance.allowance),
})),
pagination: d.pagination,
}));
}
}
34 changes: 34 additions & 0 deletions src/core/Msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ import {
MsgUndelegate,
StakingMsg,
} from './staking/msgs';
import {
MsgCreatePeriodicVestingAccount,
MsgCreateVestingAccount,
MsgDonateAllVestingTokens,
VestingMsg,
} from './vesting/msgs';
import {
MsgStoreCode,
MsgMigrateCode,
Expand Down Expand Up @@ -91,6 +97,7 @@ export type Msg =
| OracleMsg
| SlashingMsg
| StakingMsg
| VestingMsg
| WasmMsg
| IbcTransferMsg
| IbcClientMsg
Expand All @@ -109,6 +116,7 @@ export namespace Msg {
| OracleMsg.Amino
| SlashingMsg.Amino
| StakingMsg.Amino
| VestingMsg.Amino
| WasmMsg.Amino
| IbcTransferMsg.Amino
| CrisisMsg.Amino;
Expand All @@ -123,6 +131,7 @@ export namespace Msg {
| OracleMsg.Data
| SlashingMsg.Data
| StakingMsg.Data
| VestingMsg.Data
| WasmMsg.Data
| IbcTransferMsg.Data
| IbcClientMsg.Data
Expand All @@ -140,6 +149,7 @@ export namespace Msg {
| OracleMsg.Proto
| SlashingMsg.Proto
| StakingMsg.Proto
| VestingMsg.Proto
| WasmMsg.Proto
| IbcTransferMsg.Proto
| IbcClientMsg.Proto
Expand Down Expand Up @@ -238,6 +248,14 @@ export namespace Msg {
case 'cosmos-sdk/MsgEditValidator':
return MsgEditValidator.fromAmino(data, isClassic);

// vesting
case 'cosmos-sdk/MsgCreatePeriodicVestingAccount':
return MsgCreatePeriodicVestingAccount.fromAmino(data, isClassic);
case 'cosmos-sdk/MsgCreateVestingAccount':
return MsgCreateVestingAccount.fromAmino(data, isClassic);
case 'cosmos-sdk/MsgDonateAllVestingTokens':
return MsgDonateAllVestingTokens.fromAmino(data, isClassic);

// wasm
case 'wasm/MsgStoreCode':
return MsgStoreCode.fromAmino(data, isClassic);
Expand Down Expand Up @@ -335,6 +353,14 @@ export namespace Msg {
case '/cosmos.staking.v1beta1.MsgEditValidator':
return MsgEditValidator.fromData(data, isClassic);

// vesting
case '/cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount':
return MsgCreatePeriodicVestingAccount.fromData(data, isClassic);
case '/cosmos.vesting.v1beta1.MsgCreateVestingAccount':
return MsgCreateVestingAccount.fromData(data, isClassic);
case '/cosmos.vesting.v1beta1.MsgDonateAllVestingTokens':
return MsgDonateAllVestingTokens.fromData(data, isClassic);

// wasm
case '/terra.wasm.v1beta1.MsgStoreCode':
case '/cosmwasm.wasm.v1.MsgStoreCode':
Expand Down Expand Up @@ -480,6 +506,14 @@ export namespace Msg {
case '/cosmos.staking.v1beta1.MsgEditValidator':
return MsgEditValidator.unpackAny(proto, isClassic);

// vesting
case '/cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount':
return MsgCreatePeriodicVestingAccount.unpackAny(proto, isClassic);
case '/cosmos.vesting.v1beta1.MsgCreateVestingAccount':
return MsgCreateVestingAccount.unpackAny(proto, isClassic);
case '/cosmos.vesting.v1beta1.MsgDonateAllVestingTokens':
return MsgDonateAllVestingTokens.unpackAny(proto, isClassic);

// wasm
case '/terra.wasm.v1beta1.MsgStoreCode':
case '/cosmwasm.wasm.v1.MsgStoreCode':
Expand Down
3 changes: 3 additions & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export * from './staking/Validator';
// Treasury
export * from './treasury/PolicyConstraints';

// Vesting
export * from './vesting';

// Upgrade
export * from './upgrade';

Expand Down
86 changes: 86 additions & 0 deletions src/core/vesting/Period.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Coins } from '../Coins';
import { Period as Period_pb } from '@terra-money/terra.proto/cosmos/vesting/v1beta1/vesting';

import { JSONSerializable } from '../../util/json';
import * as Long from 'long';
/**
* Period defines a length of time and amount of coins that will vest.
*/
export class Period extends JSONSerializable<
Period.Amino,
Period.Data,
Period.Proto
> {
public amount: Coins;

/**
* @param length
* @param amount
*/
constructor(public length: number, amount: Coins.Input) {
super();
this.amount = new Coins(amount);
}

public static fromAmino(data: Period.Amino, _?: boolean): Period {
_;
const { length, amount } = data;
return new Period(Number.parseInt(length), Coins.fromAmino(amount));
}

public toAmino(_?: boolean): Period.Amino {
_;
const { length, amount } = this;

const res: Period.Amino = {
length: length.toFixed(),
amount: amount.toAmino(),
};
return res;
}

public static fromData(data: Period.Data, _?: boolean): Period {
_;
const { length, amount } = data;
return new Period(Number.parseInt(length), Coins.fromData(amount));
}

public toData(_?: boolean): Period.Data {
_;
const { length, amount } = this;

const res: Period.Amino = {
length: length.toFixed(),
amount: amount.toData(),
};
return res;
}

public static fromProto(proto: Period.Proto, _?: boolean): Period {
_;
return new Period(proto.length.toNumber(), Coins.fromProto(proto.amount));
}

public toProto(_?: boolean): Period.Proto {
_;
const { length, amount } = this;
return Period_pb.fromPartial({
length: Long.fromNumber(length),
amount: amount.toProto(),
});
}
}

export namespace Period {
export interface Amino {
length: string;
amount: Coins.Amino;
}

export interface Data {
length: string;
amount: Coins.Data;
}

export type Proto = Period_pb;
}
2 changes: 2 additions & 0 deletions src/core/vesting/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './Period';
export * from './msgs';
26 changes: 26 additions & 0 deletions src/core/vesting/msgs/MsgCreatePeriodicVestingAccount.data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"@type": "/cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount",
"from_address": "terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v",
"to_address": "terra1av6ssz7k4xpc5nsjj2884nugakpp874ae0krx7",
"start_time": "1658121411",
"vesting_periods": [
{
"length": "100",
"amount": [
{
"denom": "uluna",
"amount": "1000000"
}
]
},
{
"length": "200",
"amount": [
{
"denom": "uluna",
"amount": "2000000"
}
]
}
]
}
23 changes: 23 additions & 0 deletions src/core/vesting/msgs/MsgCreatePeriodicVestingAccount.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const data = require('./MsgCreatePeriodicVestingAccount.data.json');
import { MsgCreatePeriodicVestingAccount } from './MsgCreatePeriodicVestingAccount';

describe('MsgCreatePeriodicVestingAccount', () => {
it('deserializes', () => {
MsgCreatePeriodicVestingAccount.fromData(data);
});

it('conversion', () => {
const obj = MsgCreatePeriodicVestingAccount.fromData(data);
const p = obj.toProto(false);
expect(obj.from_address).toStrictEqual(p.fromAddress);
expect(obj.start_time).toStrictEqual(p.startTime.toNumber());
expect(obj.to_address).toStrictEqual(p.toAddress);
expect(obj.vesting_periods.toString()).toStrictEqual(
p.vestingPeriods.toString()
);
const d = obj.toData(false);
expect(obj).toStrictEqual(MsgCreatePeriodicVestingAccount.fromData(d));
const a = obj.toAmino(false);
expect(obj).toStrictEqual(MsgCreatePeriodicVestingAccount.fromAmino(a));
});
});
Loading