Skip to content

Commit

Permalink
fix vesting account
Browse files Browse the repository at this point in the history
  • Loading branch information
yun-yeo committed Sep 30, 2021
1 parent b7ed073 commit 499a71a
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 206 deletions.
4 changes: 2 additions & 2 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
@@ -1,6 +1,6 @@
{
"name": "@terra-money/terra.js",
"version": "2.0.12",
"version": "2.0.13",
"description": "The JavaScript SDK for Terra",
"license": "MIT",
"author": "Terraform Labs, PTE.",
Expand Down
4 changes: 0 additions & 4 deletions src/client/lcd/api/AuthAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ describe('AuthAPI', () => {
);

expect(acct instanceof Account).toBe(true);
expect(acct.coins.toData()).toContainEqual({
denom: expect.any(String),
amount: expect.any(String),
});
});

// TODO: - after merging CosmosSDK@v0.43.x restore vesting account test
Expand Down
8 changes: 0 additions & 8 deletions src/client/lcd/api/AuthAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ export class AuthAPI extends BaseAPI {
const { result } = await this.c.get<
Account.Data | LazyGradedVestingAccount.Data
>(`/auth/accounts/${address}`, params);

// Until columbus-4 it used to return coins from /auth/accounts
if (!result.value.coins) {
result.value.coins = (
await this.c.get<Coins.Data>(`/bank/balances/${address}`, params)
).result;
}

if (result.type === 'core/Account') {
return Account.fromData(result);
} else {
Expand Down
36 changes: 4 additions & 32 deletions src/core/auth/Account.data.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
[{
[
{
"type": "core/Account",
"value": {
"address": "terra1h0d5kq5p64jcyqysvja3h2gysxnfudk9h73fnn",
"coins": [{
"denom": "ukrw",
"amount": "3981685437"
},
{
"denom": "uluna",
"amount": "2041"
},
{
"denom": "umnt",
"amount": "363613"
}
],
"public_key": {
"type": "tendermint/PubKeySecp256k1",
"value": "Av0uQ9R72aq0dgu1H+F1+1p2daQLl0JsWhwkA07ftTq/"
Expand All @@ -27,10 +15,6 @@
"type": "core/Account",
"value": {
"address": "terra1fex9f78reuwhfsnc8sun6mz8rl9zwqh03fhwf3",
"coins": [{
"denom": "ukrw",
"amount": "15464712273121303"
}],
"public_key": {
"type": "tendermint/PubKeySecp256k1",
"value": "AxYEJ7m2BMIzrugTG5Rl8Pz2RNU6eGfnsn2TfMXWEruf"
Expand All @@ -43,10 +27,6 @@
"type": "core/Account",
"value": {
"address": "terra12fm3tql2uu0gheuj3st9cwz7ml97tq9mla88c2",
"coins": [{
"denom": "ukrw",
"amount": "1077000000"
}],
"public_key": {
"type": "tendermint/PubKeySecp256k1",
"value": "AvBeqhogW0wd7OtF8M8hJ/P1A/IBY1+uNvBO/tbVlfq2"
Expand All @@ -59,11 +39,6 @@
"type": "core/Account",
"value": {
"address": "terra1kcc65k0ru6qq946ztqljxd67d5wltqstln5d5k",
"coins": [],
"public_key": {
"type": "tendermint/PubKeySecp256k1",
"value": "AsPdLO1QwuajkAP/MlVe17WwTimT7gUAE2iXDjaScrxH"
},
"account_number": "987828",
"sequence": "28"
}
Expand All @@ -72,10 +47,7 @@
"type": "core/Account",
"value": {
"address": "terra1ax7xtll5v6u6vdnymxa4k4648w80zhkggl0u24",
"coins": [{
"denom": "ukrw",
"amount": "31999000000"
}],

"public_key": {
"type": "tendermint/PubKeySecp256k1",
"value": "A/vzuSK9wCAvmFXorv/KTbUFsF9Av5r9XuplqF+4OLfR"
Expand All @@ -84,4 +56,4 @@
"sequence": "65"
}
}
]
]
24 changes: 0 additions & 24 deletions src/core/auth/Account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ describe('Account', () => {
type: 'core/Account',
value: {
address: 'terra12fm3tql2uu0gheuj3st9cwz7ml97tq9mla88c2',
coins: [
{
denom: 'ukrw',
amount: '1077000000',
},
{
denom: 'uluna',
amount: '10203920',
},
],
public_key: {
type: 'tendermint/PubKeySecp256k1',
value: 'AvBeqhogW0wd7OtF8M8hJ/P1A/IBY1+uNvBO/tbVlfq2',
Expand All @@ -31,10 +21,6 @@ describe('Account', () => {
const acct = Account.fromData(data);
expect(acct).toMatchObject({
address: 'terra12fm3tql2uu0gheuj3st9cwz7ml97tq9mla88c2',
coins: new Coins({
ukrw: '1077000000',
uluna: '10203920',
}),
public_key: {
value: 'AvBeqhogW0wd7OtF8M8hJ/P1A/IBY1+uNvBO/tbVlfq2',
},
Expand All @@ -50,7 +36,6 @@ describe('Account', () => {
type: 'core/Account',
value: {
address: '',
coins: [],
public_key: null,
account_number: '0',
sequence: '0',
Expand All @@ -63,9 +48,6 @@ describe('Account', () => {
it('serializes accounts correctly', () => {
const acct = new Account(
'terra12fm3tql2uu0gheuj3st9cwz7ml97tq9mla88c2',
new Coins({
uluna: 10203920,
}),
new PublicKey('tendermint/PubKeySecp256k1', 'abc'),
251248,
58
Expand All @@ -75,12 +57,6 @@ describe('Account', () => {
type: 'core/Account',
value: {
address: 'terra12fm3tql2uu0gheuj3st9cwz7ml97tq9mla88c2',
coins: [
{
denom: 'uluna',
amount: '10203920',
},
],
public_key: {
type: 'tendermint/PubKeySecp256k1',
value: 'abc',
Expand Down
9 changes: 2 additions & 7 deletions src/core/auth/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ export class Account extends JSONSerializable<Account.Data> {
* Creates a new Account object, holding information about a basic account.
*
* @param address account address
* @param coins account's balance
* @param public_key account's public key information
* @param account_number account number on the blockchain
* @param sequence sequence number, or number of transactions that have been posted
*/
constructor(
public address: AccAddress,
public coins: Coins,
public public_key: PublicKey | null,
public account_number: number,
public sequence: number
Expand All @@ -27,12 +25,11 @@ export class Account extends JSONSerializable<Account.Data> {
}

public toData(): Account.Data {
const { address, coins, public_key, account_number, sequence } = this;
const { address, public_key, account_number, sequence } = this;
return {
type: 'core/Account',
value: {
address,
coins: coins.toData(),
public_key: public_key ? public_key.toData() : null,
account_number: account_number.toFixed(),
sequence: sequence.toFixed(),
Expand All @@ -42,12 +39,11 @@ export class Account extends JSONSerializable<Account.Data> {

public static fromData(data: Account.Data): Account {
const {
value: { address, coins, public_key, account_number, sequence },
value: { address, public_key, account_number, sequence },
} = data;

return new Account(
address || '',
Coins.fromData(coins),
public_key ? PublicKey.fromData(public_key) : null,
Number.parseInt(account_number) || 0,
Number.parseInt(sequence) || 0
Expand All @@ -58,7 +54,6 @@ export class Account extends JSONSerializable<Account.Data> {
export namespace Account {
export interface Value {
address: AccAddress;
coins: Coins.Data;
public_key: PublicKey.Data | null;
account_number: string;
sequence: string;
Expand Down
148 changes: 89 additions & 59 deletions src/core/auth/LazyGradedVestingAccount.data.json
Original file line number Diff line number Diff line change
@@ -1,64 +1,94 @@
[{
"type": "core/LazyGradedVestingAccount",
"value": {
"address": "terra1upg95nlwkfkrq4hhjrn3k9s6ud0aqx36gwnlsn",
"coins": [{
"denom": "ukrw",
"amount": "3952727625434"
},
{
"denom": "uluna",
"amount": "48919046"
},
{
"denom": "umnt",
"amount": "35243811596"
},
{
"denom": "usdr",
"amount": "1212381"
},
{
"denom": "uusd",
"amount": "474532"
}
],
"public_key": null,
"account_number": "684082",
"sequence": "0",
"original_vesting": [{
"denom": "uluna",
"amount": "5000000000000"
}],
"delegated_free": [],
"delegated_vesting": [{
"denom": "uluna",
"amount": "1338029091449"
}],
"end_time": "0",
"vesting_schedules": [{
"denom": "uluna",
"schedules": [{
"start_time": "1558677600",
"end_time": "1561356000",
"ratio": "0.100000000000000000"
},
{
"start_time": "1561356000",
"end_time": "1587708000",
"ratio": "0.270000000000000000"
},
{
"start_time": "1587708000",
"end_time": "1600927200",
"ratio": "0.480000000000000000"
[
{
"type": "core/LazyGradedVestingAccount",
"value": {
"base_vesting_account": {
"base_account": {
"address": "terra1dp0taj85ruc299rkdvzp4z5pfg6z6swaed74e6",
"public_key": {
"type": "tendermint/PubKeyMultisigThreshold",
"value": {
"threshold": "2",
"pubkeys": [
{
"type": "tendermint/PubKeySecp256k1",
"value": "AyETa9Y9ihObzeRPWMP0MBAa0Mqune3I+5KonOCPTtkv"
},
{
"type": "tendermint/PubKeySecp256k1",
"value": "AzzLltyI4MzxLpcmS1vfpXJeAk/sgS1eVYmvXgFpGRtg"
},
{
"type": "tendermint/PubKeySecp256k1",
"value": "AnZjvWmye3JPEL95xRcGeFRf4o8pHDK0dkZjf6B9D4FA"
}
]
}
},
"account_number": "317776",
"sequence": "61"
},
"original_vesting": [{ "denom": "usdr", "amount": "1000000000000000" }],
"delegated_free": [{ "denom": "uluna", "amount": "57620630000008" }],
"delegated_vesting": []
},
"vesting_schedules": [
{
"start_time": "1600927200",
"end_time": "1603519200",
"ratio": "0.150000000000000000"
"denom": "usdr",
"schedules": [
{
"start_time": "1556085600",
"end_time": "1558677600",
"ratio": "0.100000000000000000"
},
{
"start_time": "1587708000",
"end_time": "1590300000",
"ratio": "0.100000000000000000"
},
{
"start_time": "1619244000",
"end_time": "1621836000",
"ratio": "0.100000000000000000"
},
{
"start_time": "1650780000",
"end_time": "1653372000",
"ratio": "0.100000000000000000"
},
{
"start_time": "1682316000",
"end_time": "1684908000",
"ratio": "0.100000000000000000"
},
{
"start_time": "1713938400",
"end_time": "1716530400",
"ratio": "0.100000000000000000"
},
{
"start_time": "1745474400",
"end_time": "1748066400",
"ratio": "0.100000000000000000"
},
{
"start_time": "1777010400",
"end_time": "1779602400",
"ratio": "0.100000000000000000"
},
{
"start_time": "1808546400",
"end_time": "1811138400",
"ratio": "0.100000000000000000"
},
{
"start_time": "1840168800",
"end_time": "1842760800",
"ratio": "0.100000000000000000"
}
]
}
]
}]
}
}
}]
]
Loading

0 comments on commit 499a71a

Please sign in to comment.