@witnet/sdk 1.0.15 → 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.
Files changed (40) hide show
  1. package/dist/package.json +13 -13
  2. package/dist/src/bin/helpers.d.ts +1 -0
  3. package/dist/src/bin/helpers.d.ts.map +1 -1
  4. package/dist/src/bin/helpers.js +34 -5
  5. package/dist/src/lib/crypto/payloads/DataRequestPayload.d.ts +7 -4
  6. package/dist/src/lib/crypto/payloads/DataRequestPayload.d.ts.map +1 -1
  7. package/dist/src/lib/crypto/payloads/DataRequestPayload.js +42 -16
  8. package/dist/src/lib/crypto/payloads.d.ts.map +1 -1
  9. package/dist/src/lib/crypto/payloads.js +1 -2
  10. package/dist/src/lib/crypto/signer.js +12 -9
  11. package/dist/src/lib/crypto/transmitters.js +2 -2
  12. package/dist/src/lib/crypto/types.d.ts.map +1 -1
  13. package/dist/src/lib/crypto/types.js +1 -2
  14. package/dist/src/lib/radon/index.d.ts +4 -2
  15. package/dist/src/lib/radon/index.d.ts.map +1 -1
  16. package/dist/src/lib/radon/index.js +50 -32
  17. package/dist/src/lib/radon/types.d.ts +31 -27
  18. package/dist/src/lib/radon/types.d.ts.map +1 -1
  19. package/dist/src/lib/radon/types.js +88 -46
  20. package/dist/src/lib/radon/utils.js +3 -3
  21. package/dist/src/lib/rpc/provider.d.ts +12 -0
  22. package/dist/src/lib/rpc/provider.d.ts.map +1 -1
  23. package/dist/src/lib/rpc/provider.js +11 -1
  24. package/dist/witnet/assets/index.d.ts +1 -2
  25. package/dist/witnet/assets/modals/index.d.ts +1 -2
  26. package/dist/witnet/assets/modals/web3/eth.js +3 -3
  27. package/dist/witnet/assets/modals/web3/ipfs.d.ts +1 -2
  28. package/dist/witnet/assets/modals/web3/ipfs.js +11 -9
  29. package/dist/witnet/assets/modals/web3/wit.js +4 -4
  30. package/dist/witnet/assets/requests.js +6 -51
  31. package/package.json +13 -13
  32. package/src/bin/cli/inspect.js +103 -13
  33. package/src/bin/cli/radon.js +157 -79
  34. package/src/bin/cli/wallet.js +4 -6
  35. package/src/bin/helpers.js +37 -4
  36. package/src/bin/toolkit.js +2 -2
  37. package/witnet/assets/modals/web3/eth.js +2 -2
  38. package/witnet/assets/modals/web3/ipfs.js +9 -6
  39. package/witnet/assets/modals/web3/wit.js +3 -3
  40. package/witnet/assets/requests.js +5 -51
@@ -98,7 +98,7 @@ async function execRadonBytecode (bytecode, ...flags) {
98
98
  throw EvalError("invalid hex string")
99
99
  } else {
100
100
  const npx = os.type() === "Windows_NT" ? "npx.cmd" : "npx"
101
- return cmd(npx, "witnet", "radon", "dry-run", bytecode, ...flags)
101
+ return cmd(npx, "witsdk", "radon", "dry-run", bytecode, ...flags)
102
102
  // .catch((err) => {
103
103
  // let errorMessage = err.message.split('\n').slice(1).join('\n').trim()
104
104
  // const errorRegex = /.*^error: (?<message>.*)$.*/gm
@@ -369,8 +369,8 @@ function checkRpcWildcards (wildcards) {
369
369
  } else if (typeof wildcards === "string") {
370
370
  if (isWildcard(wildcards)) {
371
371
  const char = wildcards.charAt(1)
372
- if (char < "1" || char > "9") {
373
- throw Error("RPC: wildcards not in range [1 .. 9]")
372
+ if (char < "0" || char > "9") {
373
+ throw Error("RPC: wildcards not in range [0 .. 9]")
374
374
  }
375
375
  }
376
376
  }
@@ -392,10 +392,25 @@ function replaceWildcards (obj, args) {
392
392
  ? replaceWildcards(value, args)
393
393
  : value
394
394
  )
395
+ } else if (obj && typeof obj === "object") {
396
+ obj = replaceObjectWildcards(obj, args)
395
397
  }
396
398
  return obj
397
399
  }
398
400
 
401
+ function replaceObjectWildcards(obj, args) {
402
+ return Object.fromEntries(
403
+ Object.entries(obj).map(([key, value]) => {
404
+ for (let argIndex = 0; argIndex < args.length; argIndex ++) {
405
+ const wildcard = `\\${argIndex}\\`
406
+ key = key.replaceAll(wildcard, args[argIndex])
407
+ value = replaceWildcards(value, args)
408
+ }
409
+ return [key, value]
410
+ })
411
+ )
412
+ }
413
+
399
414
  function spliceWildcard (obj, argIndex, argValue, argsCount) {
400
415
  if (obj && typeof obj === "string") {
401
416
  const wildcard = `\\${argIndex}\\`
@@ -716,7 +731,7 @@ function traceTransactionReceipt (receipt) {
716
731
  mblue(receipt.recipients.filter((pkh, index, array) => index === array.indexOf(pkh)))
717
732
  }`)
718
733
  }
719
- if (receipt?.fees) console.info(` > Fee: ${yellow(receipt.fees.toString(2))}`)
734
+ if (receipt?.fees) console.info(` > Network fee: ${yellow(receipt.fees.toString(2))}`)
720
735
  if (receipt?.value) console.info(` > Value: ${myellow(receipt.value.toString(2))}`)
721
736
  if (receipt?.weight) console.info(` > Weight: ${mgreen(commas(receipt.weight))}`)
722
737
  if (receipt?.witnesses) {
@@ -771,6 +786,23 @@ async function traceTransaction (transmitter, options) {
771
786
  return receipt
772
787
  }
773
788
 
789
+ function unescapeSlashes(str) {
790
+ // add another escaped slash if the string ends with an odd
791
+ // number of escaped slashes which will crash JSON.parse
792
+ let parsedStr = str.replace(/(^|[^\\])(\\\\)*\\$/, "$&\\");
793
+
794
+ // escape unescaped double quotes to prevent error with
795
+ // added double quotes in json string
796
+ parsedStr = parsedStr.replace(/(^|[^\\])((\\\\)*")/g, "$1\\$2");
797
+
798
+ try {
799
+ parsedStr = JSON.parse(`"${parsedStr}"`);
800
+ } catch(e) {
801
+ return str;
802
+ }
803
+ return parsedStr ;
804
+ }
805
+
774
806
  module.exports = {
775
807
  colors: {
776
808
  bblue,
@@ -837,4 +869,5 @@ module.exports = {
837
869
  replaceWildcards,
838
870
  spliceWildcard,
839
871
  txJsonReplacer,
872
+ unescapeSlashes,
840
873
  }
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  /// IMPORTS ===========================================================================================================
4
4
 
@@ -18,7 +18,7 @@ const {
18
18
 
19
19
  /// CONSTANTS =======================================================================================================
20
20
 
21
- const version = "2.0.8"
21
+ const version = "2.0.21"
22
22
  const toolkitDownloadUrlBase = `https://github.com/witnet/witnet-rust/releases/download/${version}/`
23
23
  const toolkitDownloadNames = {
24
24
  win32: (arch) => `witnet_toolkit-${arch}-pc-windows-msvc.exe`,
@@ -16,13 +16,13 @@ module.exports = {
16
16
  }),
17
17
  WitOracleEthGetBalance: new RadonModal({
18
18
  retrieval: retrievals.JsonRPC({
19
- rpc: retrievals.rpc.eth.getBalance("\\1\\"),
19
+ rpc: retrievals.rpc.eth.getBalance("\\0\\"),
20
20
  script: RadonScript(types.RadonString).asFloat().floor(),
21
21
  }),
22
22
  }),
23
23
  WitOracleEthGetTransactionReceipt: new RadonModal({
24
24
  retrieval: retrievals.JsonRPC({
25
- rpc: retrievals.rpc.eth.getTransactionByHash("\\1\\"),
25
+ rpc: retrievals.rpc.eth.getTransactionByHash("\\0\\"),
26
26
  script: RadonScript(types.RadonString).parseJSONMap(),
27
27
  }),
28
28
  }),
@@ -1,8 +1,6 @@
1
1
  const {
2
2
  RadonModal,
3
3
  RadonScript,
4
- // filters,
5
- // reducers,
6
4
  retrievals,
7
5
  types,
8
6
  } = require("../../../../src/lib/radon")
@@ -10,10 +8,15 @@ const {
10
8
  module.exports = {
11
9
  WitOracleIpfsFileExists: new RadonModal({
12
10
  retrieval: retrievals.HttpHead({
13
- headers: {},
14
- script: RadonScript(types.RadonString),
11
+ script: RadonScript(types.RadonMap)
12
+ .getString("etag")
13
+ .slice(1, -1)
14
+ .match(types.RadonBoolean, { "\\0\\": true }, false)
15
15
  }),
16
16
  }),
17
- WitOracleIpfsFileSha256: {},
18
- WitOracleIpfsFileSha256Sealed: {},
17
+ WitOracleIpfsFileSha256: new RadonModal({
18
+ retrieval: retrievals.HttpGet({
19
+ script: RadonScript(types.RadonBytes).hash()
20
+ })
21
+ })
19
22
  }
@@ -8,14 +8,14 @@ const {
8
8
  module.exports = {
9
9
  WitOracleWitGetBalance: new RadonModal({
10
10
  retrieval: retrievals.JsonRPC({
11
- rpc: retrievals.rpc.wit.getBalance("\\1\\"),
11
+ rpc: retrievals.rpc.wit.getBalance("\\0\\"),
12
12
  script: RadonScript(types.RadonString).parseJSONMap().getMap("result").values(),
13
13
  }),
14
14
  }),
15
15
  WitOracleWitGetValueTransfer: new RadonModal({
16
16
  retrieval: retrievals.JsonRPC({
17
- rpc: retrievals.rpc.wit.getValueTransfer("\\1\\", "\\2\\"),
18
- script: RadonScript(types.RadonString).parseJSONMap().getMap("result").getMap("\\2\\").values(),
17
+ rpc: retrievals.rpc.wit.getValueTransfer("\\0\\", "\\1\\"),
18
+ script: RadonScript(types.RadonString).parseJSONMap().getMap("result").getMap("\\1\\").values(),
19
19
  }),
20
20
  }),
21
21
  }
@@ -8,38 +8,16 @@ const {
8
8
  } = require("../../src/lib/radon")
9
9
 
10
10
  module.exports = {
11
-
12
11
  defi: {
13
12
  tickers: {
14
13
  crypto: {
15
14
  WitOracleRequestPriceCryptoWitUsdt6: new RadonRequest({
16
15
  sources: [
17
16
  retrievals.HttpGet({
18
- url: "https://api-cloud.bitmart.com/spot/v1/ticker?symbol=WIT_USDT",
19
- script: RadonScript(types.RadonString)
20
- .parseJSONMap()
21
- .getMap("data")
22
- .getArray("tickers")
23
- .getMap(0)
24
- .getFloat("last_price")
25
- .multiply(1e6)
26
- .round(),
27
- }),
28
- retrievals.HttpGet({
29
- url: "https://data.gateapi.io/api2/1/ticker/wit_usdt",
30
- script: RadonScript(types.RadonString)
31
- .parseJSONMap()
32
- .getFloat("last")
33
- .multiply(1e6)
34
- .round(),
35
- }),
36
- retrievals.HttpGet({
37
- url: "https://www.mexc.com/open/api/v2/market/ticker?symbol=WIT_USDT",
17
+ url: "https://api.mexc.com/api/v3/ticker/price?symbol=WITUSDT",
38
18
  script: RadonScript(types.RadonString)
39
19
  .parseJSONMap()
40
- .getArray("data")
41
- .getMap(0)
42
- .getFloat("last")
20
+ .getFloat("price")
43
21
  .multiply(1e6)
44
22
  .round(),
45
23
  }),
@@ -50,35 +28,11 @@ module.exports = {
50
28
  WitOracleRequestPriceCryptoUsdtWit9: new RadonRequest({
51
29
  sources: [
52
30
  retrievals.HttpGet({
53
- url: "https://api-cloud.bitmart.com/spot/v1/ticker?symbol=WIT_USDT",
54
- script: RadonScript(types.RadonString)
55
- .parseJSONMap()
56
- .getMap("data")
57
- .getArray("tickers")
58
- .getMap(0)
59
- .getFloat("last_price")
60
- .power(-1)
61
- .multiply(1e9)
62
- .round(),
63
- }),
64
- retrievals.HttpGet({
65
- url: "https://data.gateapi.io/api2/1/ticker/wit_usdt",
31
+ url: "https://api.mexc.com/api/v3/ticker/price?symbol=WITUSDT",
66
32
  script: RadonScript(types.RadonString)
67
33
  .parseJSONMap()
68
- .getFloat("last")
69
- .power(-1)
70
- .multiply(1e9)
71
- .round(),
72
- }),
73
- retrievals.HttpGet({
74
- url: "https://www.mexc.com/open/api/v2/market/ticker?symbol=WIT_USDT",
75
- script: RadonScript(types.RadonString)
76
- .parseJSONMap()
77
- .getArray("data")
78
- .getMap(0)
79
- .getFloat("last")
80
- .power(-1)
81
- .multiply(1e9)
34
+ .getFloat("price")
35
+ .multiply(1e6)
82
36
  .round(),
83
37
  }),
84
38
  ],