-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from Agoric/main
Deploy 'main' to production
- Loading branch information
Showing
7 changed files
with
348 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare module 'stridejs/module/codegen/stride/vesting/vesting' { | ||
import { StridePeriodicVestingAccount } from 'stridejs/types/codegen/stride/vesting/vesting'; | ||
export { StridePeriodicVestingAccount }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { Pubkey } from '@cosmjs/amino'; | ||
import { Uint64 } from '@cosmjs/math'; | ||
import { decodePubkey } from '@cosmjs/proto-signing'; | ||
import { assert } from '@cosmjs/utils'; | ||
import { | ||
BaseAccount, | ||
ModuleAccount, | ||
} from 'cosmjs-types/cosmos/auth/v1beta1/auth'; | ||
import { | ||
BaseVestingAccount, | ||
ContinuousVestingAccount, | ||
DelayedVestingAccount, | ||
PeriodicVestingAccount, | ||
} from 'cosmjs-types/cosmos/vesting/v1beta1/vesting'; | ||
import { Any } from 'cosmjs-types/google/protobuf/any'; | ||
import { StridePeriodicVestingAccount } from 'stridejs/main/codegen/stride/vesting/vesting'; | ||
|
||
export interface Account { | ||
/** Bech32 account address */ | ||
readonly address: string; | ||
readonly pubkey: Pubkey | null; | ||
readonly accountNumber: number; | ||
readonly sequence: number; | ||
} | ||
|
||
function uint64FromProto(input: number | bigint): Uint64 { | ||
return Uint64.fromString(input.toString()); | ||
} | ||
|
||
function accountFromBaseAccount(input: BaseAccount): Account { | ||
const { address, pubKey, accountNumber, sequence } = input; | ||
const pubkey = pubKey ? decodePubkey(pubKey) : null; | ||
return { | ||
address: address, | ||
pubkey: pubkey, | ||
accountNumber: uint64FromProto(accountNumber).toNumber(), | ||
sequence: uint64FromProto(sequence).toNumber(), | ||
}; | ||
} | ||
|
||
/** | ||
* Represents a generic function that takes an `Any` encoded account from the chain | ||
* and extracts some common `Account` information from it. | ||
*/ | ||
export type AccountParser = (any: Any) => Account; | ||
|
||
/** | ||
* Basic implementation of AccountParser. This is supposed to support the most relevant | ||
* common Cosmos SDK account types. If you need support for exotic account types, | ||
* you'll need to write your own account decoder. | ||
*/ | ||
export function accountFromAny(input: Any): Account { | ||
const { typeUrl, value } = input; | ||
|
||
switch (typeUrl) { | ||
// auth | ||
|
||
case '/cosmos.auth.v1beta1.BaseAccount': | ||
return accountFromBaseAccount(BaseAccount.decode(value)); | ||
case '/cosmos.auth.v1beta1.ModuleAccount': { | ||
const baseAccount = ModuleAccount.decode(value).baseAccount; | ||
assert(baseAccount); | ||
return accountFromBaseAccount(baseAccount); | ||
} | ||
|
||
// vesting | ||
|
||
case '/cosmos.vesting.v1beta1.BaseVestingAccount': { | ||
const baseAccount = BaseVestingAccount.decode(value)?.baseAccount; | ||
assert(baseAccount); | ||
return accountFromBaseAccount(baseAccount); | ||
} | ||
case '/cosmos.vesting.v1beta1.ContinuousVestingAccount': { | ||
const baseAccount = | ||
ContinuousVestingAccount.decode(value)?.baseVestingAccount?.baseAccount; | ||
assert(baseAccount); | ||
return accountFromBaseAccount(baseAccount); | ||
} | ||
case '/cosmos.vesting.v1beta1.DelayedVestingAccount': { | ||
const baseAccount = | ||
DelayedVestingAccount.decode(value)?.baseVestingAccount?.baseAccount; | ||
assert(baseAccount); | ||
return accountFromBaseAccount(baseAccount); | ||
} | ||
case '/cosmos.vesting.v1beta1.PeriodicVestingAccount': { | ||
const baseAccount = | ||
PeriodicVestingAccount.decode(value)?.baseVestingAccount?.baseAccount; | ||
assert(baseAccount); | ||
return accountFromBaseAccount(baseAccount); | ||
} | ||
|
||
// custom | ||
|
||
case '/stride.vesting.StridePeriodicVestingAccount': { | ||
const baseAccount = | ||
StridePeriodicVestingAccount.decode(value).baseVestingAccount | ||
.baseAccount; | ||
assert(baseAccount); | ||
return accountFromBaseAccount(baseAccount); | ||
} | ||
|
||
default: | ||
throw new Error(`Unsupported type: '${typeUrl}'`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.