-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
324 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,48 @@ | ||
import { AccAddress, Coin } from '../../../core'; | ||
import { APIParams } from '../APIRequester'; | ||
import { BaseAPI } from './BaseAPI'; | ||
|
||
export interface ForwardingStats { | ||
num_of_accounts: number; | ||
num_of_forwards: number; | ||
total_forwarded: Coin; | ||
} | ||
|
||
export namespace ForwardingStats { | ||
export interface Data { | ||
num_of_accounts: string; | ||
num_of_forwards: string; | ||
total_forwarded: Coin.Data; | ||
} | ||
} | ||
|
||
export class ForwardingAPI extends BaseAPI { | ||
public async address( | ||
channel: string, | ||
recipient: string, | ||
params: APIParams = {} | ||
): Promise<AccAddress> { | ||
return this.c | ||
.get<{ address: AccAddress }>( | ||
`/noble/forwarding/v1/address/${channel}/${recipient}`, | ||
params | ||
) | ||
.then(d => d.address); | ||
} | ||
|
||
public async stats( | ||
channel: string, | ||
params: APIParams = {} | ||
): Promise<ForwardingStats> { | ||
return this.c | ||
.get<ForwardingStats.Data>( | ||
`/noble/forwarding/v1/stats/${channel}`, | ||
params | ||
) | ||
.then(d => ({ | ||
num_of_accounts: parseInt(d.num_of_accounts), | ||
num_of_forwards: parseInt(d.num_of_forwards), | ||
total_forwarded: Coin.fromData(d.total_forwarded), | ||
})); | ||
} | ||
} |
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 @@ | ||
export * from './msgs'; |
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,99 @@ | ||
import { JSONSerializable } from '../../../util/json'; | ||
import { AccAddress } from '../../bech32'; | ||
import { Any } from '@initia/initia.proto/google/protobuf/any'; | ||
import { MsgClearAccount as MsgClearAccount_pb } from '@initia/initia.proto/noble/forwarding/v1/tx'; | ||
|
||
export class MsgClearForwardingAccount extends JSONSerializable< | ||
MsgClearForwardingAccount.Amino, | ||
MsgClearForwardingAccount.Data, | ||
MsgClearForwardingAccount.Proto | ||
> { | ||
/** | ||
* @param signer | ||
* @param address | ||
*/ | ||
constructor(public signer: AccAddress, public address: string) { | ||
super(); | ||
} | ||
|
||
public static fromAmino( | ||
data: MsgClearForwardingAccount.Amino | ||
): MsgClearForwardingAccount { | ||
const { | ||
value: { signer, address }, | ||
} = data; | ||
return new MsgClearForwardingAccount(signer, address); | ||
} | ||
|
||
public toAmino(): MsgClearForwardingAccount.Amino { | ||
const { signer, address } = this; | ||
return { | ||
type: 'noble/forwarding/ClearAccount', | ||
value: { | ||
signer, | ||
address, | ||
}, | ||
}; | ||
} | ||
|
||
public static fromData( | ||
data: MsgClearForwardingAccount.Data | ||
): MsgClearForwardingAccount { | ||
const { signer, address } = data; | ||
return new MsgClearForwardingAccount(signer, address); | ||
} | ||
|
||
public toData(): MsgClearForwardingAccount.Data { | ||
const { signer, address } = this; | ||
return { | ||
'@type': '/noble.forwarding.v1.MsgClearAccount', | ||
signer, | ||
address, | ||
}; | ||
} | ||
|
||
public static fromProto( | ||
data: MsgClearForwardingAccount.Proto | ||
): MsgClearForwardingAccount { | ||
return new MsgClearForwardingAccount(data.signer, data.address); | ||
} | ||
|
||
public toProto(): MsgClearForwardingAccount.Proto { | ||
const { signer, address } = this; | ||
return MsgClearAccount_pb.fromPartial({ | ||
signer, | ||
address, | ||
}); | ||
} | ||
|
||
public packAny(): Any { | ||
return Any.fromPartial({ | ||
typeUrl: '/noble.forwarding.v1.MsgClearAccount', | ||
value: MsgClearAccount_pb.encode(this.toProto()).finish(), | ||
}); | ||
} | ||
|
||
public static unpackAny(msgAny: Any): MsgClearForwardingAccount { | ||
return MsgClearForwardingAccount.fromProto( | ||
MsgClearAccount_pb.decode(msgAny.value) | ||
); | ||
} | ||
} | ||
|
||
export namespace MsgClearForwardingAccount { | ||
export interface Amino { | ||
type: 'noble/forwarding/ClearAccount'; | ||
value: { | ||
signer: AccAddress; | ||
address: string; | ||
}; | ||
} | ||
|
||
export interface Data { | ||
'@type': '/noble.forwarding.v1.MsgClearAccount'; | ||
signer: AccAddress; | ||
address: string; | ||
} | ||
|
||
export type Proto = MsgClearAccount_pb; | ||
} |
Oops, something went wrong.