forked from hodlone/taro-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmintApi.ts
99 lines (87 loc) · 2.64 KB
/
mintApi.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { ClientReadableStream } from '@grpc/grpc-js';
import { promisify } from 'util';
import { TapdClientOptions } from './';
import { loadProto } from './proto';
import {
CancelBatchRequestPartial,
CancelBatchResponse,
FinalizeBatchRequestPartial,
FinalizeBatchResponse,
ListBatchRequestPartial,
ListBatchResponse,
MintAssetRequestPartial,
MintAssetResponse,
MintClient,
MintEvent,
SubscribeMintEventsRequestPartial,
} from './types';
import { ProtoGrpcType } from './types/mint';
/**
* @MintApi API interface for tapd's Mint RPC sub-server.
*/
export class MintApi {
/**
* @create Create a new MintApi instance.
*/
static create(options: TapdClientOptions) {
const { proto, credentials, params } = loadProto<ProtoGrpcType>(
'mintrpc/mint.proto',
options
);
return new MintApi(
new proto.mintrpc.Mint(options.socket, credentials, params)
);
}
/**
* @client The grpc client to contact daemon.
*/
client: MintClient;
constructor(client: MintClient) {
this.client = client;
}
/**
* @mintAsset will attempt to mint the set of assets (async by default to
* ensure proper batching) specified in the request. The pending batch is
* returned that shows the other pending assets that are part of the next
* batch. This call will block until the operation succeeds (asset is staged
* in the batch) or fails.
*/
async mintAsset(
request: MintAssetRequestPartial = {}
): Promise<MintAssetResponse> {
return promisify(this.client.MintAsset.bind(this.client))(request);
}
/**
* @finalizeBatch FinalizeBatch will attempt to finalize the current pending batch.
*/
async finalizeBatch(
request: FinalizeBatchRequestPartial = {}
): Promise<FinalizeBatchResponse> {
return promisify(this.client.FinalizeBatch.bind(this.client))(request);
}
/**
* @cancelBatch CancelBatch will attempt to cancel the current pending batch.
*/
async cancelBatch(
request: CancelBatchRequestPartial = {}
): Promise<CancelBatchResponse> {
return promisify(this.client.CancelBatch.bind(this.client))(request);
}
/**
* @listBatches ListBatches will attempt to cancel the current pending batch.
*/
async listBatches(
request: ListBatchRequestPartial = {}
): Promise<ListBatchResponse> {
return promisify(this.client.ListBatches.bind(this.client))(request);
}
/**
* @subscribeMintEvents allows a caller to subscribe to mint events for asset
* creation batches.
*/
subscribeMintEvents(
request: SubscribeMintEventsRequestPartial = {}
): ClientReadableStream<MintEvent> {
return this.client.SubscribeMintEvents(request);
}
}