Implement requestAirdrop
This commit is contained in:
@ -16,9 +16,9 @@ export type TransactionSignature = string;
|
||||
/**
|
||||
* @typedef {string} TransactionId
|
||||
*/
|
||||
export type TransactionId= string;
|
||||
export type TransactionId = string;
|
||||
|
||||
type RpcRequest = (methodName: string, args: Array<string>) => any;
|
||||
type RpcRequest = (methodName: string, args: Array<string|number>) => any;
|
||||
|
||||
function createRpcRequest(url): RpcRequest {
|
||||
const server = jayson(
|
||||
@ -88,6 +88,12 @@ const GetFinalityRpcResult = struct({
|
||||
error: 'any?',
|
||||
result: 'number?',
|
||||
});
|
||||
const RequestAirdropRpcResult = struct({
|
||||
jsonrpc: struct.literal('2.0'),
|
||||
id: 'string',
|
||||
error: 'any?',
|
||||
result: 'boolean?',
|
||||
});
|
||||
|
||||
function sleep(duration = 0) {
|
||||
return new Promise((accept) => {
|
||||
@ -158,9 +164,14 @@ export class Connection {
|
||||
return Number(res.result);
|
||||
}
|
||||
|
||||
async requestAirdrop(account: Account, amount: number): Promise<void> {
|
||||
console.log(`TODO: airdrop ${amount} to ${account.publicKey}`);
|
||||
await sleep(500); // TODO
|
||||
async requestAirdrop(to: PublicKey, amount: number): Promise<void> {
|
||||
const unsafeRes = await this._rpcRequest('requestAirdrop', [to, amount]);
|
||||
const res = RequestAirdropRpcResult(unsafeRes);
|
||||
if (res.error) {
|
||||
throw new Error(res.error.message);
|
||||
}
|
||||
assert(typeof res.result !== 'undefined');
|
||||
assert(res.result);
|
||||
}
|
||||
|
||||
async sendTokens(from: Account, to: PublicKey, amount: number): Promise<TransactionSignature> {
|
||||
|
Reference in New Issue
Block a user