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
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ let blockchainRID = "7d565d92fd15bd1cdac2dc276cbcbc5581349d05a9e94ba919e1155ef4d
|
|
|
41
41
|
// default pool size is 10. Applications that do hundreds of requests
|
|
42
42
|
// per second may consider setting this a bit higher, for example 100.
|
|
43
43
|
// It *may* speed things up a bit. You may also set an opitional
|
|
44
|
-
// poolinginterval in milliseconds, default is set to 500, a fail over
|
|
44
|
+
// poolinginterval in milliseconds, default is set to 500, a fail over
|
|
45
45
|
// config wich include attemps per endpoint and attempt interval, default is 3 and 500.
|
|
46
46
|
let rest = restClient.createRestClient([`http://localhost:7741`], blockchainRID, 5, 1000);
|
|
47
47
|
|
|
@@ -74,9 +74,9 @@ await req.sign(signatureProviderA);
|
|
|
74
74
|
//await req.sign(signerPrivKeyA, signerPubKeyA);
|
|
75
75
|
|
|
76
76
|
// ... or by the addSignature() function
|
|
77
|
-
let
|
|
77
|
+
let digestToSign = req.getDigestToSign();
|
|
78
78
|
// Sign the buffer externally.
|
|
79
|
-
let signatureFromB = askUserBToSign(
|
|
79
|
+
let signatureFromB = askUserBToSign(digestToSign);
|
|
80
80
|
// and add the signature to the request
|
|
81
81
|
req.addSignature(signerPubKeyB, signatureFromB);
|
|
82
82
|
|
|
@@ -119,7 +119,7 @@ function askUserBToSign(buffer) {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
// The complex signature process can, however, even be implemented in
|
|
122
|
-
// a signatureProvider. Once you have a callback like the one above,
|
|
122
|
+
// a signatureProvider. Once you have a callback like the one above,
|
|
123
123
|
// it's a simple matter of making a signature provider:
|
|
124
124
|
let signatureProviderB {
|
|
125
125
|
pubKey: signerPubKeyB,
|
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,20 @@ function checkGTXSignatures(txHash, gtx) {
|
|
|
1733
1754
|
}
|
|
1734
1755
|
return true;
|
|
1735
1756
|
}
|
|
1757
|
+
function newSignatureProvider(keyPair) {
|
|
1758
|
+
let pub, priv;
|
|
1759
|
+
if (keyPair) {
|
|
1760
|
+
priv = ensureBuffer(keyPair.privKey);
|
|
1761
|
+
pub = keyPair.pubKey ? ensureBuffer(keyPair.pubKey) : createPublicKey(priv);
|
|
1762
|
+
}
|
|
1763
|
+
else {
|
|
1764
|
+
({ privKey: priv, pubKey: pub } = makeKeyPair());
|
|
1765
|
+
}
|
|
1766
|
+
return {
|
|
1767
|
+
pubKey: pub,
|
|
1768
|
+
sign: (digest) => __awaiter$5(this, void 0, void 0, function* () { return signDigest(digest, priv); })
|
|
1769
|
+
};
|
|
1770
|
+
}
|
|
1736
1771
|
|
|
1737
1772
|
var gtx = /*#__PURE__*/Object.freeze({
|
|
1738
1773
|
__proto__: null,
|
|
@@ -1744,6 +1779,7 @@ var gtx = /*#__PURE__*/Object.freeze({
|
|
|
1744
1779
|
emptyGtx: emptyGtx,
|
|
1745
1780
|
getDigestToSign: getDigestToSign,
|
|
1746
1781
|
gtvTxBody: gtvTxBody,
|
|
1782
|
+
newSignatureProvider: newSignatureProvider,
|
|
1747
1783
|
serialize: serialize,
|
|
1748
1784
|
sign: sign,
|
|
1749
1785
|
signRawTransaction: signRawTransaction
|
|
@@ -1811,21 +1847,32 @@ var logger = /*#__PURE__*/Object.freeze({
|
|
|
1811
1847
|
warning: warning
|
|
1812
1848
|
});
|
|
1813
1849
|
|
|
1814
|
-
|
|
1815
|
-
|
|
1850
|
+
var __awaiter$4 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1851
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1852
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1853
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1854
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1855
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1856
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1857
|
+
});
|
|
1858
|
+
};
|
|
1816
1859
|
function createClient(restApiClient, blockchainRID, functionNames) {
|
|
1817
1860
|
functionNames.push("message");
|
|
1818
1861
|
function transaction(gtx$1) {
|
|
1819
1862
|
return {
|
|
1820
1863
|
gtx: gtx$1,
|
|
1821
|
-
sign: function (
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1864
|
+
sign: function (privOrSigProv, pubKey) {
|
|
1865
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
1866
|
+
debug(`signing transaction with ${privOrSigProv instanceof Buffer
|
|
1867
|
+
? "privkey: " + privOrSigProv.toString("hex")
|
|
1868
|
+
: "signature provider [pubkey: " + privOrSigProv.pubKey + "]"}`);
|
|
1869
|
+
if (privOrSigProv instanceof Buffer) {
|
|
1870
|
+
yield sign(this.gtx, privOrSigProv, pubKey);
|
|
1871
|
+
}
|
|
1872
|
+
else {
|
|
1873
|
+
yield sign(this.gtx, privOrSigProv);
|
|
1874
|
+
}
|
|
1875
|
+
});
|
|
1829
1876
|
},
|
|
1830
1877
|
getTxRID: function () {
|
|
1831
1878
|
return this.getDigestToSign();
|
|
@@ -1877,8 +1924,13 @@ function createClient(restApiClient, blockchainRID, functionNames) {
|
|
|
1877
1924
|
addFunctions(req);
|
|
1878
1925
|
return req;
|
|
1879
1926
|
},
|
|
1880
|
-
query: function (
|
|
1881
|
-
|
|
1927
|
+
query: function (nameOrObject, queryArguments) {
|
|
1928
|
+
if (typeof nameOrObject === "string") {
|
|
1929
|
+
return restApiClient.query(nameOrObject, queryArguments);
|
|
1930
|
+
}
|
|
1931
|
+
else {
|
|
1932
|
+
return restApiClient.query(nameOrObject);
|
|
1933
|
+
}
|
|
1882
1934
|
},
|
|
1883
1935
|
};
|
|
1884
1936
|
return client;
|
|
@@ -1951,7 +2003,7 @@ class EmptyListOfUrlsException extends Error {
|
|
|
1951
2003
|
}
|
|
1952
2004
|
}
|
|
1953
2005
|
|
|
1954
|
-
var __awaiter$
|
|
2006
|
+
var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1955
2007
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1956
2008
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1957
2009
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -1960,50 +2012,8 @@ var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|
|
1960
2012
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1961
2013
|
});
|
|
1962
2014
|
};
|
|
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
2015
|
function handleRequest(method, path, endpoint, postObject) {
|
|
2006
|
-
return __awaiter$
|
|
2016
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
2007
2017
|
if (method == Method.GET) {
|
|
2008
2018
|
return yield get(path, endpoint);
|
|
2009
2019
|
}
|
|
@@ -2018,7 +2028,7 @@ function handleRequest(method, path, endpoint, postObject) {
|
|
|
2018
2028
|
* @param endpoint
|
|
2019
2029
|
*/
|
|
2020
2030
|
function get(path, endpoint) {
|
|
2021
|
-
return __awaiter$
|
|
2031
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
2022
2032
|
debug("GET URL " + new URL(path, endpoint).href);
|
|
2023
2033
|
try {
|
|
2024
2034
|
const response = yield fetch(new URL(path, endpoint).href);
|
|
@@ -2041,7 +2051,7 @@ function get(path, endpoint) {
|
|
|
2041
2051
|
* @param requestBody request body
|
|
2042
2052
|
*/
|
|
2043
2053
|
function post(path, endpoint, requestBody) {
|
|
2044
|
-
return __awaiter$
|
|
2054
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
2045
2055
|
debug("POST URL " + new URL(path, endpoint).href);
|
|
2046
2056
|
debug("POST body " + JSON.stringify(requestBody));
|
|
2047
2057
|
if (Buffer.isBuffer(requestBody)) {
|
|
@@ -2079,6 +2089,58 @@ function post(path, endpoint, requestBody) {
|
|
|
2079
2089
|
}
|
|
2080
2090
|
});
|
|
2081
2091
|
}
|
|
2092
|
+
|
|
2093
|
+
var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2094
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
2095
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
2096
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
2097
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
2098
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
2099
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2100
|
+
});
|
|
2101
|
+
};
|
|
2102
|
+
function getBrid(urlBase, chainId) {
|
|
2103
|
+
if (chainId >= 0) {
|
|
2104
|
+
const url = `${urlBase}/brid/iid_${chainId}`;
|
|
2105
|
+
return fetch(url).then((response) => {
|
|
2106
|
+
if (response.ok)
|
|
2107
|
+
return response.text();
|
|
2108
|
+
throw new GetBridFromChainException(chainId, response.statusText);
|
|
2109
|
+
});
|
|
2110
|
+
}
|
|
2111
|
+
else {
|
|
2112
|
+
const url = `${urlBase}/_debug`;
|
|
2113
|
+
return fetch(url).then((response) => {
|
|
2114
|
+
if (response.ok)
|
|
2115
|
+
return response
|
|
2116
|
+
.json()
|
|
2117
|
+
.then((json) => json.blockchain[json.blockchain.length - 1].brid);
|
|
2118
|
+
throw new GetBridFromChainException(chainId, response.statusText);
|
|
2119
|
+
});
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
function requestWithRetry(method, path, config, postObject) {
|
|
2123
|
+
return __awaiter$2(this, void 0, void 0, function* () {
|
|
2124
|
+
let statusCode, rspBody, error;
|
|
2125
|
+
const noRetryStatusCodes = [200, 400, 409, 500];
|
|
2126
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2127
|
+
for (const _endpoint of config.endpointPool) {
|
|
2128
|
+
const endpoint = nextEndpoint(config.endpointPool);
|
|
2129
|
+
for (let attempt = 0; attempt < config.attemptsPerEndpoint; attempt++) {
|
|
2130
|
+
({ error, statusCode, rspBody } = yield handleRequest(method, path, endpoint, postObject));
|
|
2131
|
+
if (noRetryStatusCodes.includes(statusCode)) {
|
|
2132
|
+
return { error, statusCode, rspBody };
|
|
2133
|
+
}
|
|
2134
|
+
if (statusCode == 503) {
|
|
2135
|
+
break;
|
|
2136
|
+
}
|
|
2137
|
+
info(`${method} request failed on ${endpoint}. Attempt: ${attempt + 1} / ${config.attemptsPerEndpoint}`);
|
|
2138
|
+
yield sleep(config.attemptInterval);
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
return { error, statusCode, rspBody };
|
|
2142
|
+
});
|
|
2143
|
+
}
|
|
2082
2144
|
function nextEndpoint(endpointPool) {
|
|
2083
2145
|
return endpointPool[Math.floor(Math.random() * endpointPool.length)];
|
|
2084
2146
|
}
|
|
@@ -2087,7 +2149,6 @@ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
|
2087
2149
|
var restclientutil = /*#__PURE__*/Object.freeze({
|
|
2088
2150
|
__proto__: null,
|
|
2089
2151
|
getBrid: getBrid,
|
|
2090
|
-
handleRequest: handleRequest,
|
|
2091
2152
|
nextEndpoint: nextEndpoint,
|
|
2092
2153
|
requestWithRetry: requestWithRetry,
|
|
2093
2154
|
sleep: sleep
|
|
@@ -2112,15 +2173,6 @@ function createRestClient(endpointPool, blockchainRID, maxSockets = 10, pollingI
|
|
|
2112
2173
|
attemptsPerEndpoint: (failOverConfig === null || failOverConfig === void 0 ? void 0 : failOverConfig.attemptsPerEndpoint) || 3,
|
|
2113
2174
|
attemptInterval: (failOverConfig === null || failOverConfig === void 0 ? void 0 : failOverConfig.attemptInterval) || 500,
|
|
2114
2175
|
},
|
|
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
2176
|
getTransaction: function (txRID, callback) {
|
|
2125
2177
|
return __awaiter$1(this, void 0, void 0, function* () {
|
|
2126
2178
|
if (!validTxRID(txRID)) {
|
|
@@ -2132,16 +2184,6 @@ function createRestClient(endpointPool, blockchainRID, maxSockets = 10, pollingI
|
|
|
2132
2184
|
}
|
|
2133
2185
|
});
|
|
2134
2186
|
},
|
|
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
2187
|
postTransaction: function (serializedTransaction, callback) {
|
|
2146
2188
|
return __awaiter$1(this, void 0, void 0, function* () {
|
|
2147
2189
|
if (!Buffer.isBuffer(serializedTransaction)) {
|
|
@@ -2154,76 +2196,6 @@ function createRestClient(endpointPool, blockchainRID, maxSockets = 10, pollingI
|
|
|
2154
2196
|
handlePostResponse(error, statusCode, rspBody, callback);
|
|
2155
2197
|
});
|
|
2156
2198
|
},
|
|
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
2199
|
status: function (txRID, callback) {
|
|
2228
2200
|
return __awaiter$1(this, void 0, void 0, function* () {
|
|
2229
2201
|
if (!validTxRID(txRID)) {
|
|
@@ -2235,11 +2207,7 @@ function createRestClient(endpointPool, blockchainRID, maxSockets = 10, pollingI
|
|
|
2235
2207
|
}
|
|
2236
2208
|
});
|
|
2237
2209
|
},
|
|
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) {
|
|
2210
|
+
query: function (nameOrQueryObject, queryArguments) {
|
|
2243
2211
|
return __awaiter$1(this, void 0, void 0, function* () {
|
|
2244
2212
|
// eslint-disable-next-line no-async-promise-executor
|
|
2245
2213
|
return new Promise((resolve, reject) => __awaiter$1(this, void 0, void 0, function* () {
|
|
@@ -2251,15 +2219,11 @@ function createRestClient(endpointPool, blockchainRID, maxSockets = 10, pollingI
|
|
|
2251
2219
|
resolve(result);
|
|
2252
2220
|
}
|
|
2253
2221
|
};
|
|
2254
|
-
const { error, statusCode, rspBody } = yield requestWithRetry(Method.POST, `query_gtv/${blockchainRID}`, this.config, encodeValue(toQueryObjectGTV(
|
|
2222
|
+
const { error, statusCode, rspBody } = yield requestWithRetry(Method.POST, `query_gtv/${blockchainRID}`, this.config, encodeValue(toQueryObjectGTV(nameOrQueryObject, queryArguments)));
|
|
2255
2223
|
handlePostResponse(error, statusCode, rspBody, callback);
|
|
2256
2224
|
}));
|
|
2257
2225
|
});
|
|
2258
2226
|
},
|
|
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
2227
|
waitConfirmation(txRID) {
|
|
2264
2228
|
return new Promise((resolve, reject) => {
|
|
2265
2229
|
this.status(txRID, (error$1, result) => {
|
|
@@ -2289,12 +2253,6 @@ function createRestClient(endpointPool, blockchainRID, maxSockets = 10, pollingI
|
|
|
2289
2253
|
});
|
|
2290
2254
|
});
|
|
2291
2255
|
},
|
|
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
2256
|
postAndWaitConfirmation(serializedTransaction, txRID, validate) {
|
|
2299
2257
|
if (validate === true) {
|
|
2300
2258
|
return Promise.reject("Automatic validation is not yet implemented");
|
|
@@ -2309,10 +2267,6 @@ function createRestClient(endpointPool, blockchainRID, maxSockets = 10, pollingI
|
|
|
2309
2267
|
});
|
|
2310
2268
|
});
|
|
2311
2269
|
},
|
|
2312
|
-
/**
|
|
2313
|
-
* Returns a string array with the endpoints hosting the dApp the client
|
|
2314
|
-
* is connected to
|
|
2315
|
-
*/
|
|
2316
2270
|
getEndpointPool() {
|
|
2317
2271
|
return this.config.endpointPool;
|
|
2318
2272
|
},
|
|
@@ -2351,11 +2305,11 @@ function handleGetResponse(error$1, statusCode, responseObject, callback) {
|
|
|
2351
2305
|
if (error$1) {
|
|
2352
2306
|
callback(error$1, null);
|
|
2353
2307
|
}
|
|
2354
|
-
else if (statusCode === 404) {
|
|
2308
|
+
else if (statusCode === 404) { //TODO remove
|
|
2355
2309
|
error("404 received");
|
|
2356
2310
|
callback(null, null);
|
|
2357
2311
|
}
|
|
2358
|
-
else if (statusCode
|
|
2312
|
+
else if (statusCode !== 200) {
|
|
2359
2313
|
callback(new UnexpectedStatusError(statusCode), responseObject);
|
|
2360
2314
|
}
|
|
2361
2315
|
else {
|