postchain-client 1.1.0 → 1.1.1
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/built/cjs/index.js +132 -183
- package/built/cjs/index.js.map +1 -1
- package/built/esm/index.js +196 -255
- 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 +33 -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 +13 -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 +2 -109
- 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 +204 -247
- package/built/umd/index.js.map +1 -1
- package/package.json +1 -1
package/built/cjs/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var bn_js = require('bn.js');
|
|
4
4
|
var crypto = require('crypto');
|
|
5
|
-
var secp256k1
|
|
5
|
+
var secp256k1 = require('secp256k1');
|
|
6
6
|
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
8
8
|
var n = Object.create(null);
|
|
@@ -22,7 +22,7 @@ function _interopNamespaceDefault(e) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
var crypto__namespace = /*#__PURE__*/_interopNamespaceDefault(crypto);
|
|
25
|
-
var secp256k1__namespace = /*#__PURE__*/_interopNamespaceDefault(secp256k1
|
|
25
|
+
var secp256k1__namespace = /*#__PURE__*/_interopNamespaceDefault(secp256k1);
|
|
26
26
|
|
|
27
27
|
function getAugmentedNamespace(n) {
|
|
28
28
|
if (n.__esModule) return n;
|
|
@@ -120,11 +120,18 @@ function toBuffer(key) {
|
|
|
120
120
|
function toString(buffer) {
|
|
121
121
|
return buffer.toString("hex");
|
|
122
122
|
}
|
|
123
|
-
function toQueryObjectGTV(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
123
|
+
function toQueryObjectGTV(nameOrObject, queryArguments) {
|
|
124
|
+
let name;
|
|
125
|
+
if (typeof nameOrObject === "string") {
|
|
126
|
+
name = nameOrObject;
|
|
127
|
+
return [name, Object.assign({}, queryArguments)];
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
const objectCopy = Object.assign({}, nameOrObject);
|
|
131
|
+
name = objectCopy.type;
|
|
132
|
+
delete objectCopy.type;
|
|
133
|
+
return [name, objectCopy];
|
|
134
|
+
}
|
|
128
135
|
}
|
|
129
136
|
class PgBytesInputException extends Error {
|
|
130
137
|
constructor(buffer) {
|
|
@@ -1623,6 +1630,15 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
1623
1630
|
const encode = encodeValueGtx;
|
|
1624
1631
|
const decode = decodeValueGtx;
|
|
1625
1632
|
|
|
1633
|
+
var __awaiter$5 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1634
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1635
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1636
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1637
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1638
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1639
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1640
|
+
});
|
|
1641
|
+
};
|
|
1626
1642
|
function emptyGtx(blockchainRID) {
|
|
1627
1643
|
return { blockchainRID: blockchainRID, operations: [], signers: [] };
|
|
1628
1644
|
}
|
|
@@ -1665,14 +1681,19 @@ function gtvTxBody(gtx) {
|
|
|
1665
1681
|
gtx.signers,
|
|
1666
1682
|
];
|
|
1667
1683
|
}
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1684
|
+
function sign(gtx, privOrSigProv, pubKey) {
|
|
1685
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
1686
|
+
if (privOrSigProv instanceof Buffer) {
|
|
1687
|
+
const digestToSign = getDigestToSign(gtx);
|
|
1688
|
+
const signature = signDigest(digestToSign, privOrSigProv);
|
|
1689
|
+
addSignature(pubKey || makeKeyPair(privOrSigProv).pubKey, signature, gtx);
|
|
1690
|
+
}
|
|
1691
|
+
else {
|
|
1692
|
+
const digestToSign = getDigestToSign(gtx);
|
|
1693
|
+
const signature = yield privOrSigProv.sign(digestToSign);
|
|
1694
|
+
addSignature(privOrSigProv.pubKey, signature, gtx);
|
|
1695
|
+
}
|
|
1696
|
+
});
|
|
1676
1697
|
}
|
|
1677
1698
|
function signRawTransaction(_keyPair, _rawTransaction) {
|
|
1678
1699
|
throw Error("TODO");
|
|
@@ -1733,6 +1754,15 @@ function checkGTXSignatures(txHash, gtx) {
|
|
|
1733
1754
|
}
|
|
1734
1755
|
return true;
|
|
1735
1756
|
}
|
|
1757
|
+
function newSignatureProvider(keyPair) {
|
|
1758
|
+
const { pubKey: pub, privKey: priv } = keyPair.privKey ?
|
|
1759
|
+
{ privKey: ensureBuffer(keyPair.privKey), pubKey: ensureBuffer(keyPair.pubKey) }
|
|
1760
|
+
: makeKeyPair(keyPair.privKey);
|
|
1761
|
+
return {
|
|
1762
|
+
pubKey: pub,
|
|
1763
|
+
sign: (digest) => __awaiter$5(this, void 0, void 0, function* () { return signDigest(digest, priv); })
|
|
1764
|
+
};
|
|
1765
|
+
}
|
|
1736
1766
|
|
|
1737
1767
|
var gtx = /*#__PURE__*/Object.freeze({
|
|
1738
1768
|
__proto__: null,
|
|
@@ -1744,6 +1774,7 @@ var gtx = /*#__PURE__*/Object.freeze({
|
|
|
1744
1774
|
emptyGtx: emptyGtx,
|
|
1745
1775
|
getDigestToSign: getDigestToSign,
|
|
1746
1776
|
gtvTxBody: gtvTxBody,
|
|
1777
|
+
newSignatureProvider: newSignatureProvider,
|
|
1747
1778
|
serialize: serialize,
|
|
1748
1779
|
sign: sign,
|
|
1749
1780
|
signRawTransaction: signRawTransaction
|
|
@@ -1811,21 +1842,32 @@ var logger = /*#__PURE__*/Object.freeze({
|
|
|
1811
1842
|
warning: warning
|
|
1812
1843
|
});
|
|
1813
1844
|
|
|
1814
|
-
|
|
1815
|
-
|
|
1845
|
+
var __awaiter$4 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1846
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1847
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1848
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1849
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1850
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1851
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1852
|
+
});
|
|
1853
|
+
};
|
|
1816
1854
|
function createClient(restApiClient, blockchainRID, functionNames) {
|
|
1817
1855
|
functionNames.push("message");
|
|
1818
1856
|
function transaction(gtx$1) {
|
|
1819
1857
|
return {
|
|
1820
1858
|
gtx: gtx$1,
|
|
1821
|
-
sign: function (
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1859
|
+
sign: function (privOrSigProv, pubKey) {
|
|
1860
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
1861
|
+
debug(`signing transaction with ${privOrSigProv instanceof Buffer
|
|
1862
|
+
? "privkey: " + privOrSigProv.toString("hex")
|
|
1863
|
+
: "signature provider [pubkey: " + privOrSigProv.pubKey + "]"}`);
|
|
1864
|
+
if (privOrSigProv instanceof Buffer) {
|
|
1865
|
+
yield sign(this.gtx, privOrSigProv, pubKey);
|
|
1866
|
+
}
|
|
1867
|
+
else {
|
|
1868
|
+
yield sign(this.gtx, privOrSigProv);
|
|
1869
|
+
}
|
|
1870
|
+
});
|
|
1829
1871
|
},
|
|
1830
1872
|
getTxRID: function () {
|
|
1831
1873
|
return this.getDigestToSign();
|
|
@@ -1877,8 +1919,13 @@ function createClient(restApiClient, blockchainRID, functionNames) {
|
|
|
1877
1919
|
addFunctions(req);
|
|
1878
1920
|
return req;
|
|
1879
1921
|
},
|
|
1880
|
-
query: function (
|
|
1881
|
-
|
|
1922
|
+
query: function (nameOrObject, queryArguments) {
|
|
1923
|
+
if (typeof nameOrObject === "string") {
|
|
1924
|
+
return restApiClient.query(nameOrObject, queryArguments);
|
|
1925
|
+
}
|
|
1926
|
+
else {
|
|
1927
|
+
return restApiClient.query(nameOrObject);
|
|
1928
|
+
}
|
|
1882
1929
|
},
|
|
1883
1930
|
};
|
|
1884
1931
|
return client;
|
|
@@ -1951,7 +1998,7 @@ class EmptyListOfUrlsException extends Error {
|
|
|
1951
1998
|
}
|
|
1952
1999
|
}
|
|
1953
2000
|
|
|
1954
|
-
var __awaiter$
|
|
2001
|
+
var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1955
2002
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1956
2003
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1957
2004
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -1960,50 +2007,8 @@ var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|
|
1960
2007
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1961
2008
|
});
|
|
1962
2009
|
};
|
|
1963
|
-
function getBrid(urlBase, chainId) {
|
|
1964
|
-
if (chainId >= 0) {
|
|
1965
|
-
const url = `${urlBase}/brid/iid_${chainId}`;
|
|
1966
|
-
return fetch(url).then((response) => {
|
|
1967
|
-
if (response.ok)
|
|
1968
|
-
return response.text();
|
|
1969
|
-
throw new GetBridFromChainException(chainId, response.statusText);
|
|
1970
|
-
});
|
|
1971
|
-
}
|
|
1972
|
-
else {
|
|
1973
|
-
const url = `${urlBase}/_debug`;
|
|
1974
|
-
return fetch(url).then((response) => {
|
|
1975
|
-
if (response.ok)
|
|
1976
|
-
return response
|
|
1977
|
-
.json()
|
|
1978
|
-
.then((json) => json.blockchain[json.blockchain.length - 1].brid);
|
|
1979
|
-
throw new GetBridFromChainException(chainId, response.statusText);
|
|
1980
|
-
});
|
|
1981
|
-
}
|
|
1982
|
-
}
|
|
1983
|
-
function requestWithRetry(method, path, config, postObject) {
|
|
1984
|
-
return __awaiter$2(this, void 0, void 0, function* () {
|
|
1985
|
-
let statusCode, rspBody, error;
|
|
1986
|
-
const noRetryStatusCodes = [200, 400, 409, 500];
|
|
1987
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1988
|
-
for (const _endpoint of config.endpointPool) {
|
|
1989
|
-
const endpoint = nextEndpoint(config.endpointPool);
|
|
1990
|
-
for (let attempt = 0; attempt < config.attemptsPerEndpoint; attempt++) {
|
|
1991
|
-
({ error, statusCode, rspBody } = yield handleRequest(method, path, endpoint, postObject));
|
|
1992
|
-
if (noRetryStatusCodes.includes(statusCode)) {
|
|
1993
|
-
return { error, statusCode, rspBody };
|
|
1994
|
-
}
|
|
1995
|
-
if (statusCode == 503) {
|
|
1996
|
-
break;
|
|
1997
|
-
}
|
|
1998
|
-
info(`${method} request failed on ${endpoint}. Attempt: ${attempt + 1} / ${config.attemptsPerEndpoint}`);
|
|
1999
|
-
yield sleep(config.attemptInterval);
|
|
2000
|
-
}
|
|
2001
|
-
}
|
|
2002
|
-
return { error, statusCode, rspBody };
|
|
2003
|
-
});
|
|
2004
|
-
}
|
|
2005
2010
|
function handleRequest(method, path, endpoint, postObject) {
|
|
2006
|
-
return __awaiter$
|
|
2011
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
2007
2012
|
if (method == Method.GET) {
|
|
2008
2013
|
return yield get(path, endpoint);
|
|
2009
2014
|
}
|
|
@@ -2018,7 +2023,7 @@ function handleRequest(method, path, endpoint, postObject) {
|
|
|
2018
2023
|
* @param endpoint
|
|
2019
2024
|
*/
|
|
2020
2025
|
function get(path, endpoint) {
|
|
2021
|
-
return __awaiter$
|
|
2026
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
2022
2027
|
debug("GET URL " + new URL(path, endpoint).href);
|
|
2023
2028
|
try {
|
|
2024
2029
|
const response = yield fetch(new URL(path, endpoint).href);
|
|
@@ -2041,7 +2046,7 @@ function get(path, endpoint) {
|
|
|
2041
2046
|
* @param requestBody request body
|
|
2042
2047
|
*/
|
|
2043
2048
|
function post(path, endpoint, requestBody) {
|
|
2044
|
-
return __awaiter$
|
|
2049
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
2045
2050
|
debug("POST URL " + new URL(path, endpoint).href);
|
|
2046
2051
|
debug("POST body " + JSON.stringify(requestBody));
|
|
2047
2052
|
if (Buffer.isBuffer(requestBody)) {
|
|
@@ -2079,6 +2084,58 @@ function post(path, endpoint, requestBody) {
|
|
|
2079
2084
|
}
|
|
2080
2085
|
});
|
|
2081
2086
|
}
|
|
2087
|
+
|
|
2088
|
+
var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2089
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
2090
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
2091
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
2092
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
2093
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
2094
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2095
|
+
});
|
|
2096
|
+
};
|
|
2097
|
+
function getBrid(urlBase, chainId) {
|
|
2098
|
+
if (chainId >= 0) {
|
|
2099
|
+
const url = `${urlBase}/brid/iid_${chainId}`;
|
|
2100
|
+
return fetch(url).then((response) => {
|
|
2101
|
+
if (response.ok)
|
|
2102
|
+
return response.text();
|
|
2103
|
+
throw new GetBridFromChainException(chainId, response.statusText);
|
|
2104
|
+
});
|
|
2105
|
+
}
|
|
2106
|
+
else {
|
|
2107
|
+
const url = `${urlBase}/_debug`;
|
|
2108
|
+
return fetch(url).then((response) => {
|
|
2109
|
+
if (response.ok)
|
|
2110
|
+
return response
|
|
2111
|
+
.json()
|
|
2112
|
+
.then((json) => json.blockchain[json.blockchain.length - 1].brid);
|
|
2113
|
+
throw new GetBridFromChainException(chainId, response.statusText);
|
|
2114
|
+
});
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
function requestWithRetry(method, path, config, postObject) {
|
|
2118
|
+
return __awaiter$2(this, void 0, void 0, function* () {
|
|
2119
|
+
let statusCode, rspBody, error;
|
|
2120
|
+
const noRetryStatusCodes = [200, 400, 409, 500];
|
|
2121
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2122
|
+
for (const _endpoint of config.endpointPool) {
|
|
2123
|
+
const endpoint = nextEndpoint(config.endpointPool);
|
|
2124
|
+
for (let attempt = 0; attempt < config.attemptsPerEndpoint; attempt++) {
|
|
2125
|
+
({ error, statusCode, rspBody } = yield handleRequest(method, path, endpoint, postObject));
|
|
2126
|
+
if (noRetryStatusCodes.includes(statusCode)) {
|
|
2127
|
+
return { error, statusCode, rspBody };
|
|
2128
|
+
}
|
|
2129
|
+
if (statusCode == 503) {
|
|
2130
|
+
break;
|
|
2131
|
+
}
|
|
2132
|
+
info(`${method} request failed on ${endpoint}. Attempt: ${attempt + 1} / ${config.attemptsPerEndpoint}`);
|
|
2133
|
+
yield sleep(config.attemptInterval);
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
return { error, statusCode, rspBody };
|
|
2137
|
+
});
|
|
2138
|
+
}
|
|
2082
2139
|
function nextEndpoint(endpointPool) {
|
|
2083
2140
|
return endpointPool[Math.floor(Math.random() * endpointPool.length)];
|
|
2084
2141
|
}
|
|
@@ -2087,7 +2144,6 @@ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
|
2087
2144
|
var restclientutil = /*#__PURE__*/Object.freeze({
|
|
2088
2145
|
__proto__: null,
|
|
2089
2146
|
getBrid: getBrid,
|
|
2090
|
-
handleRequest: handleRequest,
|
|
2091
2147
|
nextEndpoint: nextEndpoint,
|
|
2092
2148
|
requestWithRetry: requestWithRetry,
|
|
2093
2149
|
sleep: sleep
|
|
@@ -2112,15 +2168,6 @@ function createRestClient(endpointPool, blockchainRID, maxSockets = 10, pollingI
|
|
|
2112
2168
|
attemptsPerEndpoint: (failOverConfig === null || failOverConfig === void 0 ? void 0 : failOverConfig.attemptsPerEndpoint) || 3,
|
|
2113
2169
|
attemptInterval: (failOverConfig === null || failOverConfig === void 0 ? void 0 : failOverConfig.attemptInterval) || 500,
|
|
2114
2170
|
},
|
|
2115
|
-
/**
|
|
2116
|
-
* Retrieves the client message with the specified double-sha256 hash
|
|
2117
|
-
* @param txRID the id of the transaction
|
|
2118
|
-
* @param callback parameters (error, serializedMessage) if first
|
|
2119
|
-
* parameter is not null, an error occurred.
|
|
2120
|
-
* If first parameter is null, then the second parameter is a buffer
|
|
2121
|
-
* with the serialized client message. If no such client message exists,
|
|
2122
|
-
* the callback will be called with (null, null).
|
|
2123
|
-
*/
|
|
2124
2171
|
getTransaction: function (txRID, callback) {
|
|
2125
2172
|
return __awaiter$1(this, void 0, void 0, function* () {
|
|
2126
2173
|
if (!validTxRID(txRID)) {
|
|
@@ -2132,16 +2179,6 @@ function createRestClient(endpointPool, blockchainRID, maxSockets = 10, pollingI
|
|
|
2132
2179
|
}
|
|
2133
2180
|
});
|
|
2134
2181
|
},
|
|
2135
|
-
/**
|
|
2136
|
-
* Sends a transaction to postchain for inclusion in a block.
|
|
2137
|
-
* Use status() to monitor progress once this transaction is
|
|
2138
|
-
* posted.
|
|
2139
|
-
*
|
|
2140
|
-
* @param serializedTransaction The transaction (a buffer) to send
|
|
2141
|
-
* @param callback taking parameter (error, responseObject) if error is null
|
|
2142
|
-
* then resonseObject is also null. If error is not null, then responseObject
|
|
2143
|
-
* is an object with the string property 'error'
|
|
2144
|
-
*/
|
|
2145
2182
|
postTransaction: function (serializedTransaction, callback) {
|
|
2146
2183
|
return __awaiter$1(this, void 0, void 0, function* () {
|
|
2147
2184
|
if (!Buffer.isBuffer(serializedTransaction)) {
|
|
@@ -2154,76 +2191,6 @@ function createRestClient(endpointPool, blockchainRID, maxSockets = 10, pollingI
|
|
|
2154
2191
|
handlePostResponse(error, statusCode, rspBody, callback);
|
|
2155
2192
|
});
|
|
2156
2193
|
},
|
|
2157
|
-
/**
|
|
2158
|
-
* Retrieves a confirmation proof for a client message with the specified double-sha256
|
|
2159
|
-
* hash.
|
|
2160
|
-
* @param txRID the id of the transaction
|
|
2161
|
-
* @param callback parameters (error, responseObjectProof) if first
|
|
2162
|
-
* parameter is not null, an error occurred.
|
|
2163
|
-
* If first parameter is null, then the second parameter is an object
|
|
2164
|
-
* like the following:
|
|
2165
|
-
*
|
|
2166
|
-
* {hash: messageHashBuffer,
|
|
2167
|
-
* blockHeader: blockHeaderBuffer,
|
|
2168
|
-
* signatures: [{pubKey: pubKeyBuffer, signature: sigBuffer}, ...],
|
|
2169
|
-
* merklePath: [{side: <0|1>, hash: <hash buffer level n-1>},
|
|
2170
|
-
* ...
|
|
2171
|
-
* {side: <0|1>, hash: <hash buffer level 1>}]}
|
|
2172
|
-
*
|
|
2173
|
-
* If no such client message exists, the callback will be called with (null, null).
|
|
2174
|
-
*
|
|
2175
|
-
* The proof object can be validated using
|
|
2176
|
-
* postchain-common.util.validateMerklePath(proof.merklePath, proof.hash,
|
|
2177
|
-
* proof.blockHeader.slice(32, 64))
|
|
2178
|
-
*
|
|
2179
|
-
* The signatures must be validated agains some know trusted source for valid signers
|
|
2180
|
-
* at this specific block height.
|
|
2181
|
-
*/
|
|
2182
|
-
getConfirmationProof: function (txRID, callback) {
|
|
2183
|
-
return __awaiter$1(this, void 0, void 0, function* () {
|
|
2184
|
-
if (!validTxRID(txRID)) {
|
|
2185
|
-
callback(new UnvalidTxRidException(txRID), null);
|
|
2186
|
-
}
|
|
2187
|
-
else {
|
|
2188
|
-
const { error, statusCode, rspBody } = yield requestWithRetry(Method.GET, "tx/" +
|
|
2189
|
-
blockchainRID +
|
|
2190
|
-
"/" +
|
|
2191
|
-
txRID.toString("hex") +
|
|
2192
|
-
"/confirmationProof", this.config);
|
|
2193
|
-
const confirmationProof = {
|
|
2194
|
-
hash: undefined,
|
|
2195
|
-
blockHeader: undefined,
|
|
2196
|
-
signatures: [],
|
|
2197
|
-
merklePath: [],
|
|
2198
|
-
};
|
|
2199
|
-
if (statusCode === 200 || statusCode === 503) {
|
|
2200
|
-
confirmationProof.hash = toBuffer(rspBody.hash);
|
|
2201
|
-
confirmationProof.blockHeader = toBuffer(rspBody.blockHeader);
|
|
2202
|
-
if (rspBody.signatures) {
|
|
2203
|
-
confirmationProof.signatures = rspBody.signatures.map((item) => ({
|
|
2204
|
-
pubKey: toBuffer(item.pubKey),
|
|
2205
|
-
signature: toBuffer(item.signature),
|
|
2206
|
-
}));
|
|
2207
|
-
}
|
|
2208
|
-
if (rspBody.merklePath) {
|
|
2209
|
-
confirmationProof.merklePath = rspBody.merklePath.map((item) => {
|
|
2210
|
-
return { side: item.side, hash: toBuffer(item.hash) };
|
|
2211
|
-
});
|
|
2212
|
-
}
|
|
2213
|
-
}
|
|
2214
|
-
handleGetResponse(error, statusCode, confirmationProof, callback);
|
|
2215
|
-
}
|
|
2216
|
-
});
|
|
2217
|
-
},
|
|
2218
|
-
/**
|
|
2219
|
-
* Queries the status of a certain transaction.
|
|
2220
|
-
* @param txRID the id of the transaction
|
|
2221
|
-
* @param callback taking parameters (error, responseBody). If error is null
|
|
2222
|
-
* then responseBody is an object on the form
|
|
2223
|
-
* { status: '<confirmed|waiting|rejected|unknown>' }
|
|
2224
|
-
* If error is not null, then responseBody
|
|
2225
|
-
* is an object with the string property 'error'
|
|
2226
|
-
*/
|
|
2227
2194
|
status: function (txRID, callback) {
|
|
2228
2195
|
return __awaiter$1(this, void 0, void 0, function* () {
|
|
2229
2196
|
if (!validTxRID(txRID)) {
|
|
@@ -2235,11 +2202,7 @@ function createRestClient(endpointPool, blockchainRID, maxSockets = 10, pollingI
|
|
|
2235
2202
|
}
|
|
2236
2203
|
});
|
|
2237
2204
|
},
|
|
2238
|
-
|
|
2239
|
-
* Interfaces the query enpoint of the Rell backend. Returns either a resolved or rejected promise.
|
|
2240
|
-
* @param queryObject an object that must contain a "type" and follows this pattern: { type: "nameOfQuery", arg1: argValue1, arg2: argvalue2 }
|
|
2241
|
-
*/
|
|
2242
|
-
query: function (queryObject) {
|
|
2205
|
+
query: function (nameOrQueryObject, queryArguments) {
|
|
2243
2206
|
return __awaiter$1(this, void 0, void 0, function* () {
|
|
2244
2207
|
// eslint-disable-next-line no-async-promise-executor
|
|
2245
2208
|
return new Promise((resolve, reject) => __awaiter$1(this, void 0, void 0, function* () {
|
|
@@ -2251,15 +2214,11 @@ function createRestClient(endpointPool, blockchainRID, maxSockets = 10, pollingI
|
|
|
2251
2214
|
resolve(result);
|
|
2252
2215
|
}
|
|
2253
2216
|
};
|
|
2254
|
-
const { error, statusCode, rspBody } = yield requestWithRetry(Method.POST, `query_gtv/${blockchainRID}`, this.config, encodeValue(toQueryObjectGTV(
|
|
2217
|
+
const { error, statusCode, rspBody } = yield requestWithRetry(Method.POST, `query_gtv/${blockchainRID}`, this.config, encodeValue(toQueryObjectGTV(nameOrQueryObject, queryArguments)));
|
|
2255
2218
|
handlePostResponse(error, statusCode, rspBody, callback);
|
|
2256
2219
|
}));
|
|
2257
2220
|
});
|
|
2258
2221
|
},
|
|
2259
|
-
/**
|
|
2260
|
-
* Polls for status while waiting for response; confirmed, rejected or unknown. Returns either a resolved or rejected promise.
|
|
2261
|
-
* @param txRID the id of the transaction
|
|
2262
|
-
*/
|
|
2263
2222
|
waitConfirmation(txRID) {
|
|
2264
2223
|
return new Promise((resolve, reject) => {
|
|
2265
2224
|
this.status(txRID, (error$1, result) => {
|
|
@@ -2289,12 +2248,6 @@ function createRestClient(endpointPool, blockchainRID, maxSockets = 10, pollingI
|
|
|
2289
2248
|
});
|
|
2290
2249
|
});
|
|
2291
2250
|
},
|
|
2292
|
-
/**
|
|
2293
|
-
* Posts a transaction and polls for status while waiting for status response; confirmed, rejected or unknown. Returns either a resolved or rejected promise.
|
|
2294
|
-
* @param serializedTransaction The transaction (a buffer) to send
|
|
2295
|
-
* @param txRID the id of the transaction
|
|
2296
|
-
* @param validate true if the transaction needs to be validated
|
|
2297
|
-
*/
|
|
2298
2251
|
postAndWaitConfirmation(serializedTransaction, txRID, validate) {
|
|
2299
2252
|
if (validate === true) {
|
|
2300
2253
|
return Promise.reject("Automatic validation is not yet implemented");
|
|
@@ -2309,10 +2262,6 @@ function createRestClient(endpointPool, blockchainRID, maxSockets = 10, pollingI
|
|
|
2309
2262
|
});
|
|
2310
2263
|
});
|
|
2311
2264
|
},
|
|
2312
|
-
/**
|
|
2313
|
-
* Returns a string array with the endpoints hosting the dApp the client
|
|
2314
|
-
* is connected to
|
|
2315
|
-
*/
|
|
2316
2265
|
getEndpointPool() {
|
|
2317
2266
|
return this.config.endpointPool;
|
|
2318
2267
|
},
|