postchain-client 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/built/cjs/index.js +139 -185
- package/built/cjs/index.js.map +1 -1
- package/built/esm/index.js +203 -257
- package/built/esm/index.js.map +1 -1
- package/built/src/formatter.d.ts +2 -2
- package/built/src/formatter.js +12 -5
- package/built/src/formatter.js.map +1 -1
- package/built/src/gtx/gtx.d.ts +6 -4
- package/built/src/gtx/gtx.js +38 -9
- package/built/src/gtx/gtx.js.map +1 -1
- package/built/src/gtx/gtxclient.js +28 -12
- package/built/src/gtx/gtxclient.js.map +1 -1
- package/built/src/gtx/interfaces.d.ts +72 -3
- package/built/src/restclient/httpUtil.d.ts +4 -0
- package/built/src/restclient/httpUtil.js +91 -0
- package/built/src/restclient/httpUtil.js.map +1 -0
- package/built/src/restclient/interfaces.d.ts +56 -4
- package/built/src/restclient/restclient.js +4 -111
- package/built/src/restclient/restclient.js.map +1 -1
- package/built/src/restclient/restclientutil.d.ts +0 -1
- package/built/src/restclient/restclientutil.js +1 -79
- package/built/src/restclient/restclientutil.js.map +1 -1
- package/built/src/restclient/types.d.ts +3 -0
- package/built/src/restclient/types.js.map +1 -1
- package/built/umd/index.js +141 -187
- package/built/umd/index.js.map +1 -1
- package/package.json +4 -2
|
@@ -24,15 +24,6 @@ export function createRestClient(endpointPool, blockchainRID, maxSockets = 10, p
|
|
|
24
24
|
attemptsPerEndpoint: (failOverConfig === null || failOverConfig === void 0 ? void 0 : failOverConfig.attemptsPerEndpoint) || 3,
|
|
25
25
|
attemptInterval: (failOverConfig === null || failOverConfig === void 0 ? void 0 : failOverConfig.attemptInterval) || 500,
|
|
26
26
|
},
|
|
27
|
-
/**
|
|
28
|
-
* Retrieves the client message with the specified double-sha256 hash
|
|
29
|
-
* @param txRID the id of the transaction
|
|
30
|
-
* @param callback parameters (error, serializedMessage) if first
|
|
31
|
-
* parameter is not null, an error occurred.
|
|
32
|
-
* If first parameter is null, then the second parameter is a buffer
|
|
33
|
-
* with the serialized client message. If no such client message exists,
|
|
34
|
-
* the callback will be called with (null, null).
|
|
35
|
-
*/
|
|
36
27
|
getTransaction: function (txRID, callback) {
|
|
37
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
29
|
if (!validTxRID(txRID)) {
|
|
@@ -44,16 +35,6 @@ export function createRestClient(endpointPool, blockchainRID, maxSockets = 10, p
|
|
|
44
35
|
}
|
|
45
36
|
});
|
|
46
37
|
},
|
|
47
|
-
/**
|
|
48
|
-
* Sends a transaction to postchain for inclusion in a block.
|
|
49
|
-
* Use status() to monitor progress once this transaction is
|
|
50
|
-
* posted.
|
|
51
|
-
*
|
|
52
|
-
* @param serializedTransaction The transaction (a buffer) to send
|
|
53
|
-
* @param callback taking parameter (error, responseObject) if error is null
|
|
54
|
-
* then resonseObject is also null. If error is not null, then responseObject
|
|
55
|
-
* is an object with the string property 'error'
|
|
56
|
-
*/
|
|
57
38
|
postTransaction: function (serializedTransaction, callback) {
|
|
58
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
40
|
if (!Buffer.isBuffer(serializedTransaction)) {
|
|
@@ -66,76 +47,6 @@ export function createRestClient(endpointPool, blockchainRID, maxSockets = 10, p
|
|
|
66
47
|
handlePostResponse(error, statusCode, rspBody, callback);
|
|
67
48
|
});
|
|
68
49
|
},
|
|
69
|
-
/**
|
|
70
|
-
* Retrieves a confirmation proof for a client message with the specified double-sha256
|
|
71
|
-
* hash.
|
|
72
|
-
* @param txRID the id of the transaction
|
|
73
|
-
* @param callback parameters (error, responseObjectProof) if first
|
|
74
|
-
* parameter is not null, an error occurred.
|
|
75
|
-
* If first parameter is null, then the second parameter is an object
|
|
76
|
-
* like the following:
|
|
77
|
-
*
|
|
78
|
-
* {hash: messageHashBuffer,
|
|
79
|
-
* blockHeader: blockHeaderBuffer,
|
|
80
|
-
* signatures: [{pubKey: pubKeyBuffer, signature: sigBuffer}, ...],
|
|
81
|
-
* merklePath: [{side: <0|1>, hash: <hash buffer level n-1>},
|
|
82
|
-
* ...
|
|
83
|
-
* {side: <0|1>, hash: <hash buffer level 1>}]}
|
|
84
|
-
*
|
|
85
|
-
* If no such client message exists, the callback will be called with (null, null).
|
|
86
|
-
*
|
|
87
|
-
* The proof object can be validated using
|
|
88
|
-
* postchain-common.util.validateMerklePath(proof.merklePath, proof.hash,
|
|
89
|
-
* proof.blockHeader.slice(32, 64))
|
|
90
|
-
*
|
|
91
|
-
* The signatures must be validated agains some know trusted source for valid signers
|
|
92
|
-
* at this specific block height.
|
|
93
|
-
*/
|
|
94
|
-
getConfirmationProof: function (txRID, callback) {
|
|
95
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
if (!validTxRID(txRID)) {
|
|
97
|
-
callback(new UnvalidTxRidException(txRID), null);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
const { error, statusCode, rspBody } = yield requestWithRetry(Method.GET, "tx/" +
|
|
101
|
-
blockchainRID +
|
|
102
|
-
"/" +
|
|
103
|
-
txRID.toString("hex") +
|
|
104
|
-
"/confirmationProof", this.config);
|
|
105
|
-
const confirmationProof = {
|
|
106
|
-
hash: undefined,
|
|
107
|
-
blockHeader: undefined,
|
|
108
|
-
signatures: [],
|
|
109
|
-
merklePath: [],
|
|
110
|
-
};
|
|
111
|
-
if (statusCode === 200 || statusCode === 503) {
|
|
112
|
-
confirmationProof.hash = toBuffer(rspBody.hash);
|
|
113
|
-
confirmationProof.blockHeader = toBuffer(rspBody.blockHeader);
|
|
114
|
-
if (rspBody.signatures) {
|
|
115
|
-
confirmationProof.signatures = rspBody.signatures.map((item) => ({
|
|
116
|
-
pubKey: toBuffer(item.pubKey),
|
|
117
|
-
signature: toBuffer(item.signature),
|
|
118
|
-
}));
|
|
119
|
-
}
|
|
120
|
-
if (rspBody.merklePath) {
|
|
121
|
-
confirmationProof.merklePath = rspBody.merklePath.map((item) => {
|
|
122
|
-
return { side: item.side, hash: toBuffer(item.hash) };
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
handleGetResponse(error, statusCode, confirmationProof, callback);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
},
|
|
130
|
-
/**
|
|
131
|
-
* Queries the status of a certain transaction.
|
|
132
|
-
* @param txRID the id of the transaction
|
|
133
|
-
* @param callback taking parameters (error, responseBody). If error is null
|
|
134
|
-
* then responseBody is an object on the form
|
|
135
|
-
* { status: '<confirmed|waiting|rejected|unknown>' }
|
|
136
|
-
* If error is not null, then responseBody
|
|
137
|
-
* is an object with the string property 'error'
|
|
138
|
-
*/
|
|
139
50
|
status: function (txRID, callback) {
|
|
140
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
141
52
|
if (!validTxRID(txRID)) {
|
|
@@ -147,11 +58,7 @@ export function createRestClient(endpointPool, blockchainRID, maxSockets = 10, p
|
|
|
147
58
|
}
|
|
148
59
|
});
|
|
149
60
|
},
|
|
150
|
-
|
|
151
|
-
* Interfaces the query enpoint of the Rell backend. Returns either a resolved or rejected promise.
|
|
152
|
-
* @param queryObject an object that must contain a "type" and follows this pattern: { type: "nameOfQuery", arg1: argValue1, arg2: argvalue2 }
|
|
153
|
-
*/
|
|
154
|
-
query: function (queryObject) {
|
|
61
|
+
query: function (nameOrQueryObject, queryArguments) {
|
|
155
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
156
63
|
// eslint-disable-next-line no-async-promise-executor
|
|
157
64
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -163,15 +70,11 @@ export function createRestClient(endpointPool, blockchainRID, maxSockets = 10, p
|
|
|
163
70
|
resolve(result);
|
|
164
71
|
}
|
|
165
72
|
};
|
|
166
|
-
const { error, statusCode, rspBody } = yield requestWithRetry(Method.POST, `query_gtv/${blockchainRID}`, this.config, encodeValue(toQueryObjectGTV(
|
|
73
|
+
const { error, statusCode, rspBody } = yield requestWithRetry(Method.POST, `query_gtv/${blockchainRID}`, this.config, encodeValue(toQueryObjectGTV(nameOrQueryObject, queryArguments)));
|
|
167
74
|
handlePostResponse(error, statusCode, rspBody, callback);
|
|
168
75
|
}));
|
|
169
76
|
});
|
|
170
77
|
},
|
|
171
|
-
/**
|
|
172
|
-
* Polls for status while waiting for response; confirmed, rejected or unknown. Returns either a resolved or rejected promise.
|
|
173
|
-
* @param txRID the id of the transaction
|
|
174
|
-
*/
|
|
175
78
|
waitConfirmation(txRID) {
|
|
176
79
|
return new Promise((resolve, reject) => {
|
|
177
80
|
this.status(txRID, (error, result) => {
|
|
@@ -201,12 +104,6 @@ export function createRestClient(endpointPool, blockchainRID, maxSockets = 10, p
|
|
|
201
104
|
});
|
|
202
105
|
});
|
|
203
106
|
},
|
|
204
|
-
/**
|
|
205
|
-
* Posts a transaction and polls for status while waiting for status response; confirmed, rejected or unknown. Returns either a resolved or rejected promise.
|
|
206
|
-
* @param serializedTransaction The transaction (a buffer) to send
|
|
207
|
-
* @param txRID the id of the transaction
|
|
208
|
-
* @param validate true if the transaction needs to be validated
|
|
209
|
-
*/
|
|
210
107
|
postAndWaitConfirmation(serializedTransaction, txRID, validate) {
|
|
211
108
|
if (validate === true) {
|
|
212
109
|
return Promise.reject("Automatic validation is not yet implemented");
|
|
@@ -221,10 +118,6 @@ export function createRestClient(endpointPool, blockchainRID, maxSockets = 10, p
|
|
|
221
118
|
});
|
|
222
119
|
});
|
|
223
120
|
},
|
|
224
|
-
/**
|
|
225
|
-
* Returns a string array with the endpoints hosting the dApp the client
|
|
226
|
-
* is connected to
|
|
227
|
-
*/
|
|
228
121
|
getEndpointPool() {
|
|
229
122
|
return this.config.endpointPool;
|
|
230
123
|
},
|
|
@@ -263,11 +156,11 @@ function handleGetResponse(error, statusCode, responseObject, callback) {
|
|
|
263
156
|
if (error) {
|
|
264
157
|
callback(error, null);
|
|
265
158
|
}
|
|
266
|
-
else if (statusCode === 404) {
|
|
159
|
+
else if (statusCode === 404) { //TODO remove
|
|
267
160
|
logger.error("404 received");
|
|
268
161
|
callback(null, null);
|
|
269
162
|
}
|
|
270
|
-
else if (statusCode
|
|
163
|
+
else if (statusCode !== 200) {
|
|
271
164
|
callback(new UnexpectedStatusError(statusCode), responseObject);
|
|
272
165
|
}
|
|
273
166
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restclient.js","sourceRoot":"","sources":["../../../src/restclient/restclient.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;AACb,OAAO,
|
|
1
|
+
{"version":3,"file":"restclient.js","sourceRoot":"","sources":["../../../src/restclient/restclient.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;AACb,OAAO,EAEL,cAAc,EAId,MAAM,GAEP,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,MAAM,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,oCAAoC,EACpC,eAAe,EACf,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,MAAM,UAAU,gBAAgB,CAC9B,YAA+B,EAC/B,aAAqB,EACrB,UAAU,GAAG,EAAE,EACf,eAAe,GAAG,GAAG,EACrB,cAA+B;IAE/B,aAAa,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;IAE5C,OAAO;QACL,MAAM,EAAE;YACN,YAAY,EAAE,YAAY;YAC1B,IAAI,EAAE,EAAE,UAAU,EAAE;YACpB,eAAe;YACf,mBAAmB,EAAE,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,mBAAmB,KAAI,CAAC;YAC7D,eAAe,EAAE,CAAA,cAAc,aAAd,cAAc,uBAAd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ClientConfig, PostRequestObjects, Method, ResponseObject } from "./types";
|
|
3
3
|
export declare function getBrid(urlBase: string, chainId: number): Promise<string>;
|
|
4
4
|
export declare function requestWithRetry(method: Method, path: string, config: RestClientConfig, postObject?: PostRequestObjects | Buffer): Promise<ResponseObject>;
|
|
5
|
-
export declare function handleRequest(method: Method, path: string, endpoint: string, postObject?: PostRequestObjects | Buffer): Promise<ResponseObject>;
|
|
6
5
|
export declare function nextEndpoint(endpointPool: readonly string[]): string;
|
|
7
6
|
export declare const sleep: (ms: number) => Promise<unknown>;
|
|
@@ -8,9 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import * as logger from "../logger";
|
|
11
|
-
import { decodeValue } from "../gtx/serialization";
|
|
12
11
|
import { GetBridFromChainException } from "./errors";
|
|
13
|
-
import
|
|
12
|
+
import handleRequest from "./httpUtil";
|
|
14
13
|
export function getBrid(urlBase, chainId) {
|
|
15
14
|
if (chainId >= 0) {
|
|
16
15
|
const url = `${urlBase}/brid/iid_${chainId}`;
|
|
@@ -53,83 +52,6 @@ export function requestWithRetry(method, path, config, postObject) {
|
|
|
53
52
|
return { error, statusCode, rspBody };
|
|
54
53
|
});
|
|
55
54
|
}
|
|
56
|
-
export function handleRequest(method, path, endpoint, postObject) {
|
|
57
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
if (method == Method.GET) {
|
|
59
|
-
return yield get(path, endpoint);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
return yield post(path, endpoint, postObject);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Sends request to get data from a given API endpoint.
|
|
68
|
-
* @param path API endpoint of Rell backend
|
|
69
|
-
* @param endpoint
|
|
70
|
-
*/
|
|
71
|
-
function get(path, endpoint) {
|
|
72
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
logger.debug("GET URL " + new URL(path, endpoint).href);
|
|
74
|
-
try {
|
|
75
|
-
const response = yield fetch(new URL(path, endpoint).href);
|
|
76
|
-
if (response.status == 404) {
|
|
77
|
-
return { error: null, statusCode: response.status, rspBody: null };
|
|
78
|
-
}
|
|
79
|
-
const rspBody = yield response.json();
|
|
80
|
-
return { error: null, statusCode: response.status, rspBody };
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
logger.error(error.message);
|
|
84
|
-
return { error, statusCode: null, rspBody: null };
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Sends request to post data to a given API endpoint.
|
|
90
|
-
* @param path API endpoint of Rell backend
|
|
91
|
-
* @param endpoint
|
|
92
|
-
* @param requestBody request body
|
|
93
|
-
*/
|
|
94
|
-
function post(path, endpoint, requestBody) {
|
|
95
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
logger.debug("POST URL " + new URL(path, endpoint).href);
|
|
97
|
-
logger.debug("POST body " + JSON.stringify(requestBody));
|
|
98
|
-
if (Buffer.isBuffer(requestBody)) {
|
|
99
|
-
try {
|
|
100
|
-
const requestOptions = {
|
|
101
|
-
method: "post",
|
|
102
|
-
body: requestBody,
|
|
103
|
-
};
|
|
104
|
-
const response = yield fetch(new URL(path, endpoint).href, requestOptions);
|
|
105
|
-
return {
|
|
106
|
-
error: null,
|
|
107
|
-
statusCode: response.status,
|
|
108
|
-
rspBody: decodeValue(Buffer.from(yield response.arrayBuffer())),
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
catch (error) {
|
|
112
|
-
return { error, statusCode: null, rspBody: null };
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
try {
|
|
117
|
-
const response = yield fetch(new URL(path, endpoint).href, {
|
|
118
|
-
method: "post",
|
|
119
|
-
body: JSON.stringify(requestBody),
|
|
120
|
-
});
|
|
121
|
-
return {
|
|
122
|
-
error: null,
|
|
123
|
-
statusCode: response.status,
|
|
124
|
-
rspBody: yield response.json(),
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
return { error, statusCode: null, rspBody: null };
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
55
|
export function nextEndpoint(endpointPool) {
|
|
134
56
|
return endpointPool[Math.floor(Math.random() * endpointPool.length)];
|
|
135
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restclientutil.js","sourceRoot":"","sources":["../../../src/restclient/restclientutil.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"restclientutil.js","sourceRoot":"","sources":["../../../src/restclient/restclientutil.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAOrD,OAAO,aAAa,MAAM,YAAY,CAAC;AAEvC,MAAM,UAAU,OAAO,CAAC,OAAe,EAAE,OAAe;IACtD,IAAI,OAAO,IAAI,CAAC,EAAE;QAChB,MAAM,GAAG,GAAG,GAAG,OAAO,aAAa,OAAO,EAAE,CAAC;QAC7C,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;YAClC,IAAI,QAAQ,CAAC,EAAE;gBAAE,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;YACxC,MAAM,IAAI,yBAAyB,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;QACpE,CAAC,CAAC,CAAC;KACJ;SAAM;QACL,MAAM,GAAG,GAAG,GAAG,OAAO,SAAS,CAAC;QAChC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,E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BACF,MAAM,KAAK,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;aACrC;SACF;QACD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;IACxC,CAAC;CAAA;AAED,MAAM,UAAU,YAAY,CAAC,YAA+B;IAC1D,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;AACvE,CAAC;AACD,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/restclient/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/restclient/types.ts"],"names":[],"mappings":"AAkDA,MAAM,CAAN,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,yCAAuB,CAAA;IACvB,uCAAqB,CAAA;IACrB,qCAAmB,CAAA;IACnB,qCAAmB,CAAA;AACrB,CAAC,EALW,cAAc,KAAd,cAAc,QAKzB;AA4BD,MAAM,CAAN,IAAY,MAGX;AAHD,WAAY,MAAM;IAChB,qBAAW,CAAA;IACX,uBAAa,CAAA;AACf,CAAC,EAHW,MAAM,KAAN,MAAM,QAGjB"}
|