@opcat-labs/scrypt-ts-opcat 2.0.2 → 2.1.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.
Files changed (105) hide show
  1. package/assets/.templates/smart-contract/builtin-libs/backtrace.scrypt.map +1 -1
  2. package/assets/.templates/smart-contract/builtin-libs/backtrace.scrypt.tpl +4 -0
  3. package/assets/.templates/smart-contract/builtin-libs/genesis.scrypt.map +1 -0
  4. package/assets/.templates/smart-contract/builtin-libs/genesis.scrypt.tpl +42 -0
  5. package/assets/.templates/smart-contract/builtin-libs/genesis.transformer.json +9 -0
  6. package/assets/.templates/smart-contract/builtin-libs/p2pk.scrypt.map +1 -1
  7. package/assets/.templates/smart-contract/builtin-libs/p2pk.scrypt.tpl +3 -0
  8. package/assets/.templates/smart-contract/builtin-libs/p2pkh.scrypt.map +1 -1
  9. package/assets/.templates/smart-contract/builtin-libs/p2pkh.scrypt.tpl +3 -0
  10. package/assets/smart-contract/builtin-libs/backtrace.scrypt +16 -12
  11. package/assets/smart-contract/builtin-libs/byteStringReader.scrypt +5 -5
  12. package/assets/smart-contract/builtin-libs/byteStringWriter.scrypt +6 -6
  13. package/assets/smart-contract/builtin-libs/contextUtils.scrypt +16 -16
  14. package/assets/smart-contract/builtin-libs/genesis.scrypt +44 -0
  15. package/assets/smart-contract/builtin-libs/p2pk.scrypt +4 -1
  16. package/assets/smart-contract/builtin-libs/p2pkh.scrypt +4 -1
  17. package/assets/smart-contract/builtin-libs/stateLib.scrypt +1 -1
  18. package/assets/smart-contract/builtin-libs/stateUtils.scrypt +1 -1
  19. package/assets/smart-contract/builtin-libs/stdUtils.scrypt +12 -12
  20. package/assets/smart-contract/builtin-libs/txHashPreimageUtils.scrypt +7 -7
  21. package/assets/smart-contract/builtin-libs/txUtils.scrypt +12 -12
  22. package/assets/smart-contract/types/structs.scrypt +8 -8
  23. package/dist/cjs/features/deployGenesis.cjs +84 -31
  24. package/dist/cjs/features/deployGenesis.js.map +1 -1
  25. package/dist/cjs/providers/dryRunProvider.cjs +57 -0
  26. package/dist/cjs/providers/dryRunProvider.js.map +1 -0
  27. package/dist/cjs/providers/dummyProvider.cjs +10 -0
  28. package/dist/cjs/providers/dummyProvider.js.map +1 -1
  29. package/dist/cjs/providers/index.cjs +4 -1
  30. package/dist/cjs/providers/index.js.map +1 -1
  31. package/dist/cjs/providers/mempoolProvider.cjs +44 -0
  32. package/dist/cjs/providers/mempoolProvider.js.map +1 -1
  33. package/dist/cjs/providers/rpcProvider.cjs +46 -3
  34. package/dist/cjs/providers/rpcProvider.js.map +1 -1
  35. package/dist/cjs/providers/utxoProvider.cjs +9 -1
  36. package/dist/cjs/providers/utxoProvider.js.map +1 -1
  37. package/dist/cjs/psbt/extPsbt.cjs +8 -1
  38. package/dist/cjs/psbt/extPsbt.js.map +1 -1
  39. package/dist/cjs/psbt/psbt.cjs +3 -1
  40. package/dist/cjs/psbt/psbt.js.map +1 -1
  41. package/dist/cjs/smart-contract/builtin-libs/backtrace.cjs +59 -2
  42. package/dist/cjs/smart-contract/builtin-libs/backtrace.js.map +1 -1
  43. package/dist/cjs/smart-contract/builtin-libs/genesis.cjs +553 -0
  44. package/dist/cjs/smart-contract/builtin-libs/genesis.js.map +1 -0
  45. package/dist/cjs/smart-contract/builtin-libs/index.cjs +5 -1
  46. package/dist/cjs/smart-contract/builtin-libs/index.js.map +1 -1
  47. package/dist/cjs/smart-contract/smartContract.cjs +22 -0
  48. package/dist/cjs/smart-contract/smartContract.js.map +1 -1
  49. package/dist/esm/features/deployGenesis.js +84 -31
  50. package/dist/esm/features/deployGenesis.js.map +1 -1
  51. package/dist/esm/providers/dryRunProvider.js +53 -0
  52. package/dist/esm/providers/dryRunProvider.js.map +1 -0
  53. package/dist/esm/providers/dummyProvider.js +10 -0
  54. package/dist/esm/providers/dummyProvider.js.map +1 -1
  55. package/dist/esm/providers/index.js +2 -1
  56. package/dist/esm/providers/index.js.map +1 -1
  57. package/dist/esm/providers/mempoolProvider.js +44 -0
  58. package/dist/esm/providers/mempoolProvider.js.map +1 -1
  59. package/dist/esm/providers/rpcProvider.js +45 -2
  60. package/dist/esm/providers/rpcProvider.js.map +1 -1
  61. package/dist/esm/providers/utxoProvider.js +7 -0
  62. package/dist/esm/providers/utxoProvider.js.map +1 -1
  63. package/dist/esm/psbt/extPsbt.js +8 -1
  64. package/dist/esm/psbt/extPsbt.js.map +1 -1
  65. package/dist/esm/psbt/psbt.js +3 -1
  66. package/dist/esm/psbt/psbt.js.map +1 -1
  67. package/dist/esm/smart-contract/builtin-libs/backtrace.js +61 -4
  68. package/dist/esm/smart-contract/builtin-libs/backtrace.js.map +1 -1
  69. package/dist/esm/smart-contract/builtin-libs/genesis.js +549 -0
  70. package/dist/esm/smart-contract/builtin-libs/genesis.js.map +1 -0
  71. package/dist/esm/smart-contract/builtin-libs/index.js +1 -0
  72. package/dist/esm/smart-contract/builtin-libs/index.js.map +1 -1
  73. package/dist/esm/smart-contract/smartContract.js +23 -1
  74. package/dist/esm/smart-contract/smartContract.js.map +1 -1
  75. package/dist/types/features/deployGenesis.d.ts +39 -12
  76. package/dist/types/features/deployGenesis.d.ts.map +1 -1
  77. package/dist/types/providers/chainProvider.d.ts +12 -0
  78. package/dist/types/providers/chainProvider.d.ts.map +1 -1
  79. package/dist/types/providers/dryRunProvider.d.ts +4 -0
  80. package/dist/types/providers/dryRunProvider.d.ts.map +1 -0
  81. package/dist/types/providers/dummyProvider.d.ts +4 -2
  82. package/dist/types/providers/dummyProvider.d.ts.map +1 -1
  83. package/dist/types/providers/index.d.ts +2 -1
  84. package/dist/types/providers/index.d.ts.map +1 -1
  85. package/dist/types/providers/mempoolProvider.d.ts +4 -2
  86. package/dist/types/providers/mempoolProvider.d.ts.map +1 -1
  87. package/dist/types/providers/rpcProvider.d.ts +4 -2
  88. package/dist/types/providers/rpcProvider.d.ts.map +1 -1
  89. package/dist/types/providers/utxoProvider.d.ts +3 -0
  90. package/dist/types/providers/utxoProvider.d.ts.map +1 -1
  91. package/dist/types/psbt/extPsbt.d.ts.map +1 -1
  92. package/dist/types/psbt/psbt.d.ts.map +1 -1
  93. package/dist/types/smart-contract/builtin-libs/backtrace.d.ts +49 -0
  94. package/dist/types/smart-contract/builtin-libs/backtrace.d.ts.map +1 -1
  95. package/dist/types/smart-contract/builtin-libs/genesis.d.ts +252 -0
  96. package/dist/types/smart-contract/builtin-libs/genesis.d.ts.map +1 -0
  97. package/dist/types/smart-contract/builtin-libs/index.d.ts +1 -0
  98. package/dist/types/smart-contract/builtin-libs/index.d.ts.map +1 -1
  99. package/dist/types/smart-contract/smartContract.d.ts +20 -0
  100. package/dist/types/smart-contract/smartContract.d.ts.map +1 -1
  101. package/package.json +5 -3
  102. package/scrypt.index.json +4 -0
  103. package/src/smart-contract/builtin-libs/backtrace.ts +62 -3
  104. package/src/smart-contract/builtin-libs/genesis.ts +569 -0
  105. package/src/smart-contract/builtin-libs/index.ts +2 -1
@@ -1 +1 @@
1
- [[],[],[],[],[],[],[[7,0,16,36]],[[2,0,17,18],[8,0,17,2]],[[2,0,18,20],[8,0,18,2]],[],[],[[8,0,26,13]],[[2,0,38,2],[18,0,38,9],[42,0,39,20],[57,0,39,4],[73,0,40,16],[79,0,40,4],[91,0,41,18],[95,0,41,4]],[[4,0,43,19],[10,0,43,10],[19,0,43,19],[38,0,43,39],[67,0,43,67]],[[4,0,44,4],[12,0,44,11],[19,0,44,11],[22,0,44,27],[33,0,44,39],[46,0,44,39],[48,0,44,54],[53,0,44,59],[66,0,44,59],[68,0,44,74],[71,0,44,59],[73,0,44,80]],[],[],[[2,0,55,2],[18,0,55,9],[37,0,56,19],[51,0,56,4],[66,0,57,23],[72,0,57,4],[91,0,58,18],[97,0,58,4],[111,0,59,23],[117,0,59,4]],[[4,0,61,16],[26,0,61,10],[32,0,61,16],[41,0,61,26],[57,0,61,41],[72,0,61,56]],[[4,0,62,4],[12,0,63,6],[15,0,63,10],[33,0,63,6],[36,0,63,31],[54,0,63,6],[57,0,63,52],[60,0,63,56],[76,0,63,52],[79,0,63,74]],[],[],[[2,0,77,2],[18,0,77,9],[35,0,78,19],[49,0,78,4],[64,0,79,21],[70,0,79,4],[87,0,80,18],[93,0,80,4],[107,0,81,23],[113,0,81,4]],[[4,0,83,16],[26,0,83,10],[32,0,83,16],[41,0,83,26],[57,0,83,41],[72,0,83,56]],[[4,0,84,4],[12,0,85,6],[15,0,85,10],[31,0,85,6],[34,0,85,28],[50,0,85,6],[53,0,85,47],[56,0,85,51],[72,0,85,47],[75,0,85,69]],[],[],[[2,0,99,2],[18,0,99,9],[33,0,100,19],[47,0,100,4],[62,0,101,23],[68,0,101,4],[89,0,102,5]],[[4,0,104,4],[12,0,106,8],[30,0,107,8],[43,0,107,22],[61,0,107,8],[63,0,107,41],[69,0,108,9],[82,0,108,23],[100,0,108,9],[102,0,108,42],[105,0,108,8],[107,0,108,48],[111,0,105,6],[114,0,110,6],[121,0,110,14],[133,0,110,25],[146,0,110,39]],[[4,0,113,27],[10,0,113,10],[27,0,113,27],[40,0,113,41],[52,0,113,53]],[[4,0,114,4],[12,0,115,6],[27,0,115,6],[30,0,116,8],[49,0,116,28],[78,0,116,56],[91,0,116,70]],[[4,0,120,6],[10,0,119,10],[27,0,121,8],[40,0,121,22],[59,0,121,41],[71,0,122,8],[84,0,122,22],[96,0,122,34],[113,0,122,8],[115,0,122,52],[118,0,122,8],[120,0,122,73],[125,0,123,9],[138,0,123,23],[150,0,123,35],[168,0,123,8],[170,0,123,54],[173,0,123,8],[175,0,123,75],[177,0,123,8],[179,0,123,104]],[[4,0,126,6],[10,0,125,10],[29,0,126,6],[44,0,126,6],[46,0,126,23],[54,0,126,32],[74,0,126,51],[87,0,126,65],[99,0,126,77]],[[4,0,127,4],[11,0,127,11]],[],[]]
1
+ [[],[],[],[],[],[],[[7,0,16,36]],[[2,0,17,18],[8,0,17,2]],[[2,0,18,20],[8,0,18,2]],[],[],[[8,0,26,13]],[[2,0,45,2],[9,0,45,9],[15,0,45,39],[21,0,45,18],[43,0,45,65]],[[2,0,57,2],[18,0,57,9],[42,0,58,20],[57,0,58,4],[73,0,59,16],[79,0,59,4],[91,0,60,18],[95,0,60,4]],[[4,0,62,19],[10,0,62,10],[19,0,62,19],[38,0,62,39],[67,0,62,67]],[[4,0,63,4],[12,0,63,11],[19,0,63,11],[22,0,63,27],[33,0,63,39],[46,0,63,39],[48,0,63,54],[53,0,63,59],[66,0,63,59],[68,0,63,74],[71,0,63,59],[73,0,63,80]],[],[],[[2,0,105,2],[18,0,105,9],[37,0,106,19],[51,0,106,4],[66,0,107,23],[72,0,107,4],[91,0,108,18],[97,0,108,4],[111,0,109,23],[117,0,109,4]],[[4,0,111,16],[26,0,111,10],[32,0,111,16],[41,0,111,26],[57,0,111,41],[72,0,111,56]],[[4,0,113,4],[7,0,113,8],[10,0,113,12],[28,0,113,8],[31,0,113,33]],[[8,0,114,6],[16,0,115,8],[19,0,115,12],[35,0,115,8],[38,0,115,30],[47,0,115,40]],[],[[4,0,119,4],[12,0,120,6],[15,0,120,10],[33,0,120,6],[36,0,120,31],[54,0,120,6],[57,0,120,52],[60,0,120,56],[76,0,120,52],[79,0,120,74]],[],[],[[2,0,134,2],[18,0,134,9],[35,0,135,19],[49,0,135,4],[64,0,136,21],[70,0,136,4],[87,0,137,18],[93,0,137,4],[107,0,138,23],[113,0,138,4]],[[4,0,140,16],[26,0,140,10],[32,0,140,16],[41,0,140,26],[57,0,140,41],[72,0,140,56]],[[4,0,141,4],[12,0,142,6],[15,0,142,10],[31,0,142,6],[34,0,142,28],[50,0,142,6],[53,0,142,47],[56,0,142,51],[72,0,142,47],[75,0,142,69]],[],[],[[2,0,156,2],[18,0,156,9],[33,0,157,19],[47,0,157,4],[62,0,158,23],[68,0,158,4],[89,0,159,5]],[[4,0,161,4],[12,0,163,8],[30,0,164,8],[43,0,164,22],[61,0,164,8],[63,0,164,41],[69,0,165,9],[82,0,165,23],[100,0,165,9],[102,0,165,42],[105,0,165,8],[107,0,165,48],[111,0,162,6],[114,0,167,6],[121,0,167,14],[133,0,167,25],[146,0,167,39]],[[4,0,171,27],[10,0,171,10],[27,0,171,27],[40,0,171,41],[52,0,171,53]],[[4,0,172,4],[12,0,173,6],[27,0,173,6],[30,0,174,8],[49,0,174,28],[78,0,174,56],[91,0,174,70]],[[4,0,179,6],[10,0,178,10],[27,0,180,8],[40,0,180,22],[59,0,180,41],[71,0,181,8],[84,0,181,22],[96,0,181,34],[113,0,181,8],[115,0,181,52],[118,0,181,8],[120,0,181,73],[125,0,182,9],[138,0,182,23],[150,0,182,35],[168,0,182,8],[170,0,182,54],[173,0,182,8],[175,0,182,75],[177,0,182,8],[179,0,182,104]],[[4,0,185,6],[10,0,184,10],[29,0,185,6],[44,0,185,6],[46,0,185,23],[54,0,185,32],[74,0,185,51],[87,0,185,65],[99,0,185,77]],[[4,0,186,4],[11,0,186,11]],[],[]]
@@ -10,6 +10,7 @@ struct ChainTxVerifyResponse {
10
10
  }
11
11
 
12
12
  library Backtrace {
13
+ static const bytes GENESIS_SCRIPT_HASH = b'8f6157664f8f7cd43e6bba7f3209bb803d4d0fb2fb6e59fdc548989ed3901f15';
13
14
  static function checkPrevTxHashPreimage(TxHashPreimage txHashPreimage, bytes t_prevouts, int t_inputIndex) : bool {
14
15
  bytes txHash = TxHashPreimageUtils.getTxHashFromTxHashPreimage(txHashPreimage);
15
16
  require(txHash == t_prevouts[t_inputIndex * 36 : t_inputIndex * 36 + 32]);
@@ -17,6 +18,9 @@ library Backtrace {
17
18
  }
18
19
  static function verifyFromOutpoint(BacktraceInfo backtraceInfo, bytes t_genesisOutpoint, bytes t_selfScript, bytes t_prevTxInputList) : bool {
19
20
  ChainTxVerifyResponse res = Backtrace.verifyChainTxs(backtraceInfo, t_prevTxInputList);
21
+ if(res.prevPrevOutpoint == t_genesisOutpoint) {
22
+ require(res.prevPrevScript == Backtrace.GENESIS_SCRIPT_HASH);
23
+ }
20
24
  require(res.prevPrevOutpoint == t_genesisOutpoint || res.prevPrevScript == t_selfScript);
21
25
  return true;
22
26
  }
@@ -0,0 +1 @@
1
+ [[],[],[],[],[],[],[],[],[[9,0,117,13]],[[2,0,118,2]],[],[[2,0,180,2],[18,0,180,9],[30,0,180,30],[35,0,180,30],[39,0,180,21],[48,0,180,95],[52,0,180,82]],[],[],[],[],[],[],[[4,0,185,4],[46,0,185,11],[49,0,185,34]],[[4,0,189,4],[35,0,189,11],[38,0,189,34],[39,0,32,39]],[[4,0,192,4],[12,0,193,6],[24,0,193,6],[26,0,193,20],[28,0,193,6],[31,0,193,26],[43,0,193,26],[46,0,193,41],[47,0,55,40]],[[4,0,199,30],[10,0,199,10],[30,0,199,30],[38,0,199,38],[40,0,199,41]],[[4,0,207,22],[10,0,207,8],[24,0,207,35]],[[15,0,208,13]],[[8,0,209,22],[14,0,209,12],[24,0,209,22],[32,0,209,30]],[[8,0,210,6],[11,0,210,10],[17,0,210,10],[19,0,210,18]],[[10,0,212,8],[18,0,212,15],[22,0,212,19],[29,0,212,27],[42,0,212,15],[44,0,212,41]],[[10,0,215,8],[22,0,215,8],[25,0,215,23],[32,0,215,31],[49,0,216,10],[56,0,216,18],[69,0,217,10],[76,0,217,18],[87,0,218,10],[94,0,218,18]],[[10,0,223,8],[13,0,223,12],[19,0,223,12],[21,0,223,20]],[[12,0,224,10],[20,0,224,17],[38,0,224,17],[41,0,224,38],[48,0,224,46]],[],[],[],[[15,0,234,13]],[[8,0,235,6],[11,0,235,10],[17,0,235,10]],[[10,0,237,32],[16,0,237,14],[34,0,237,32],[46,0,237,45],[97,0,239,10],[98,0,239,17]],[[10,0,242,8],[18,0,242,15],[36,0,242,15],[39,0,242,36]],[],[],[[4,0,251,4],[20,0,251,29]],[],[]]
@@ -0,0 +1,42 @@
1
+ import "../types/structs.scrypt.tpl";
2
+ import "./txUtils.scrypt.tpl";
3
+ import "./contextUtils.scrypt.tpl";
4
+ import "@opcat-labs/scrypt-ts-opcat/assets/.templates/smart-contract/builtin-libs/txUtils.scrypt.tpl";
5
+ import "@opcat-labs/scrypt-ts-opcat/assets/.templates/smart-contract/types/structs.scrypt.tpl";
6
+ import "@opcat-labs/scrypt-ts-opcat/assets/.templates/smart-contract/builtin-libs/contextUtils.scrypt.tpl";
7
+
8
+
9
+ contract Genesis {
10
+ constructor() {
11
+ }
12
+ public function checkDeploy(TxOut[6] outputs, int outputCount, SHPreimage __scrypt_ts_shPreimage, bytes __scrypt_ts_spentAmounts, bytes __scrypt_ts_spentScriptHashes) {
13
+ require(Tx.checkPreimageSigHashType(ContextUtils.serializeSHPreimage(__scrypt_ts_shPreimage), SigHash.ALL));
14
+
15
+ int __scrypt_ts_inputCount = ContextUtils.checkSpentAmounts(__scrypt_ts_spentAmounts, __scrypt_ts_shPreimage.hashSpentAmounts);
16
+
17
+ ContextUtils.checkSpentScripts(__scrypt_ts_spentScriptHashes, __scrypt_ts_shPreimage.hashSpentScriptHashes, __scrypt_ts_inputCount);
18
+
19
+ require(__scrypt_ts_shPreimage.inputIndex == 0);
20
+ require(__scrypt_ts_inputCount <= (6));
21
+ require(outputCount > 0 && outputCount <= (6));
22
+ bytes output0ScriptHash = outputs[0].scriptHash;
23
+ bytes outputBytes = b'';
24
+ loop (6) : index {
25
+ TxOut _output = outputs[index];
26
+ if(index < outputCount) {
27
+ require(len(_output.scriptHash) > 0);
28
+ outputBytes += TxUtils.buildDataOutput(_output.scriptHash, _output.satoshis, _output.dataHash);
29
+ if(index > 0) {
30
+ require(output0ScriptHash != _output.scriptHash);
31
+ }
32
+ }
33
+ }
34
+ loop (6) : index {
35
+ if(index < __scrypt_ts_inputCount) {
36
+ bytes inputScriptHash = ContextUtils.getSpentScriptHash(__scrypt_ts_spentScriptHashes, (index));
37
+ require(output0ScriptHash != inputScriptHash);
38
+ }
39
+ }
40
+ require(hash256(outputBytes) == __scrypt_ts_shPreimage.hashOutputs);
41
+ }
42
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "success": true,
3
+ "errors": [],
4
+ "scryptfile": "smart-contract/builtin-libs/genesis.scrypt.tpl",
5
+ "sourceMapFile": "smart-contract/builtin-libs/genesis.scrypt.map",
6
+ "ctxMethods": [
7
+ "checkDeploy"
8
+ ]
9
+ }
@@ -1 +1 @@
1
- [[],[[9,0,14,13]],[[2,0,16,4],[8,0,16,21],[15,0,16,13]],[[2,0,24,4],[18,0,24,11],[25,0,24,23],[29,0,24,18]],[[4,0,25,8],[12,0,25,20],[20,0,25,15],[21,0,25,29],[26,0,25,34],[30,0,25,39],[37,0,25,15]],[],[]]
1
+ [[],[],[],[],[[9,0,14,13]],[[2,0,16,4],[8,0,16,21],[15,0,16,13]],[[2,0,24,4],[18,0,24,11],[25,0,24,23],[29,0,24,18]],[[4,0,25,8],[12,0,25,20],[20,0,25,15],[21,0,25,29],[26,0,25,34],[30,0,25,39],[37,0,25,15]],[],[]]
@@ -1,3 +1,6 @@
1
+ import "@opcat-labs/scrypt-ts-opcat/assets/.templates/smart-contract/builtin-libs/txUtils.scrypt.tpl";
2
+ import "@opcat-labs/scrypt-ts-opcat/assets/.templates/smart-contract/builtin-libs/contextUtils.scrypt.tpl";
3
+
1
4
 
2
5
  contract P2PK {
3
6
  const PubKey pubKey;
@@ -1 +1 @@
1
- [[],[[9,0,16,13]],[[2,0,18,4],[8,0,18,19],[18,0,18,13]],[[2,0,26,4],[18,0,26,11],[25,0,26,23],[29,0,26,18],[34,0,26,36],[41,0,26,28]],[[4,0,27,8],[12,0,28,12],[20,0,28,24],[28,0,28,12],[31,0,28,35],[35,0,28,40]],[[4,0,31,8],[12,0,31,20],[20,0,31,15],[21,0,31,29],[26,0,31,34],[32,0,31,15]],[],[]]
1
+ [[],[],[],[],[[9,0,16,13]],[[2,0,18,4],[8,0,18,19],[18,0,18,13]],[[2,0,26,4],[18,0,26,11],[25,0,26,23],[29,0,26,18],[34,0,26,36],[41,0,26,28]],[[4,0,27,8],[12,0,28,12],[20,0,28,24],[28,0,28,12],[31,0,28,35],[35,0,28,40]],[[4,0,31,8],[12,0,31,20],[20,0,31,15],[21,0,31,29],[26,0,31,34],[32,0,31,15]],[],[]]
@@ -1,3 +1,6 @@
1
+ import "@opcat-labs/scrypt-ts-opcat/assets/.templates/smart-contract/builtin-libs/txUtils.scrypt.tpl";
2
+ import "@opcat-labs/scrypt-ts-opcat/assets/.templates/smart-contract/builtin-libs/contextUtils.scrypt.tpl";
3
+
1
4
 
2
5
  contract P2PKH {
3
6
  const Ripemd160 addr;
@@ -6,33 +6,37 @@ import "stdUtils.scrypt";
6
6
 
7
7
 
8
8
 
9
- struct _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ChainTxVerifyResponse {
9
+ struct _opcat_labs_scrypt_ts_opcat_2_1_0__rs__ChainTxVerifyResponse {
10
10
  bytes prevPrevScript;
11
11
  bytes prevPrevOutpoint;
12
12
  }
13
13
 
14
- library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__Backtrace {
15
- static function checkPrevTxHashPreimage(_opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxHashPreimage txHashPreimage, bytes t_prevouts, int t_inputIndex) : bool {
16
- bytes txHash = _opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxHashPreimageUtils.getTxHashFromTxHashPreimage(txHashPreimage);
14
+ library _opcat_labs_scrypt_ts_opcat_2_1_0__rs__Backtrace {
15
+ static const bytes GENESIS_SCRIPT_HASH = b'8f6157664f8f7cd43e6bba7f3209bb803d4d0fb2fb6e59fdc548989ed3901f15';
16
+ static function checkPrevTxHashPreimage(_opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxHashPreimage txHashPreimage, bytes t_prevouts, int t_inputIndex) : bool {
17
+ bytes txHash = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxHashPreimageUtils.getTxHashFromTxHashPreimage(txHashPreimage);
17
18
  require(txHash == t_prevouts[t_inputIndex * 36 : t_inputIndex * 36 + 32]);
18
19
  return true;
19
20
  }
20
- static function verifyFromOutpoint(_opcat_labs_scrypt_ts_opcat_2_0_2__rs__BacktraceInfo backtraceInfo, bytes t_genesisOutpoint, bytes t_selfScript, bytes t_prevTxInputList) : bool {
21
- _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ChainTxVerifyResponse res = _opcat_labs_scrypt_ts_opcat_2_0_2__rs__Backtrace.verifyChainTxs(backtraceInfo, t_prevTxInputList);
21
+ static function verifyFromOutpoint(_opcat_labs_scrypt_ts_opcat_2_1_0__rs__BacktraceInfo backtraceInfo, bytes t_genesisOutpoint, bytes t_selfScript, bytes t_prevTxInputList) : bool {
22
+ _opcat_labs_scrypt_ts_opcat_2_1_0__rs__ChainTxVerifyResponse res = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__Backtrace.verifyChainTxs(backtraceInfo, t_prevTxInputList);
23
+ if(res.prevPrevOutpoint == t_genesisOutpoint) {
24
+ require(res.prevPrevScript == _opcat_labs_scrypt_ts_opcat_2_1_0__rs__Backtrace.GENESIS_SCRIPT_HASH);
25
+ }
22
26
  require(res.prevPrevOutpoint == t_genesisOutpoint || res.prevPrevScript == t_selfScript);
23
27
  return true;
24
28
  }
25
- static function verifyFromScript(_opcat_labs_scrypt_ts_opcat_2_0_2__rs__BacktraceInfo backtraceInfo, bytes t_genesisScript, bytes t_selfScript, bytes t_prevTxInputList) : bool {
26
- _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ChainTxVerifyResponse res = _opcat_labs_scrypt_ts_opcat_2_0_2__rs__Backtrace.verifyChainTxs(backtraceInfo, t_prevTxInputList);
29
+ static function verifyFromScript(_opcat_labs_scrypt_ts_opcat_2_1_0__rs__BacktraceInfo backtraceInfo, bytes t_genesisScript, bytes t_selfScript, bytes t_prevTxInputList) : bool {
30
+ _opcat_labs_scrypt_ts_opcat_2_1_0__rs__ChainTxVerifyResponse res = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__Backtrace.verifyChainTxs(backtraceInfo, t_prevTxInputList);
27
31
  require(res.prevPrevScript == t_genesisScript || res.prevPrevScript == t_selfScript);
28
32
  return true;
29
33
  }
30
- static function verifyChainTxs(_opcat_labs_scrypt_ts_opcat_2_0_2__rs__BacktraceInfo backtraceInfo, bytes t_prevTxInputList) : _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ChainTxVerifyResponse {
31
- require(t_prevTxInputList[backtraceInfo.prevTxInputIndex * 72 : (backtraceInfo.prevTxInputIndex + 1) * 72] == _opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxUtils.mergeInput(backtraceInfo.prevTxInput));
34
+ static function verifyChainTxs(_opcat_labs_scrypt_ts_opcat_2_1_0__rs__BacktraceInfo backtraceInfo, bytes t_prevTxInputList) : _opcat_labs_scrypt_ts_opcat_2_1_0__rs__ChainTxVerifyResponse {
35
+ require(t_prevTxInputList[backtraceInfo.prevTxInputIndex * 72 : (backtraceInfo.prevTxInputIndex + 1) * 72] == _opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxUtils.mergeInput(backtraceInfo.prevTxInput));
32
36
  bytes prevPrevTxHash = backtraceInfo.prevTxInput.prevTxHash;
33
- require(prevPrevTxHash == _opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxHashPreimageUtils.getTxHashFromTxHashPreimage(backtraceInfo.prevPrevTxPreimage));
37
+ require(prevPrevTxHash == _opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxHashPreimageUtils.getTxHashFromTxHashPreimage(backtraceInfo.prevPrevTxPreimage));
34
38
  bytes prevPrevScript = backtraceInfo.prevPrevTxPreimage.outputList[backtraceInfo.prevTxInput.prevOutputIndex * 72 + 8 : (backtraceInfo.prevTxInput.prevOutputIndex) * 72 + 8 + 32];
35
- bytes prevPrevOutpoint = prevPrevTxHash + _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.uint32ToByteString(backtraceInfo.prevTxInput.prevOutputIndex);
39
+ bytes prevPrevOutpoint = prevPrevTxHash + _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.uint32ToByteString(backtraceInfo.prevTxInput.prevOutputIndex);
36
40
  return {prevPrevScript, prevPrevOutpoint};
37
41
  }
38
42
  }
@@ -3,7 +3,7 @@ import "stdUtils.scrypt";
3
3
 
4
4
 
5
5
 
6
- library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ByteStringReader {
6
+ library _opcat_labs_scrypt_ts_opcat_2_1_0__rs__ByteStringReader {
7
7
  bytes buf;
8
8
  int pos;
9
9
  constructor(bytes buf) {
@@ -23,15 +23,15 @@ library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ByteStringReader {
23
23
  l = header;
24
24
  ret = buf[this.pos : this.pos + l];
25
25
  } else if(header == 0x4c) {
26
- l = _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.fromLEUnsigned(buf[this.pos : this.pos + 1]);
26
+ l = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.fromLEUnsigned(buf[this.pos : this.pos + 1]);
27
27
  this.pos += 1;
28
28
  ret = this.buf[this.pos : this.pos + l];
29
29
  } else if(header == 0x4d) {
30
- l = _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.fromLEUnsigned(this.buf[this.pos : this.pos + 2]);
30
+ l = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.fromLEUnsigned(this.buf[this.pos : this.pos + 2]);
31
31
  this.pos += 2;
32
32
  ret = this.buf[this.pos : this.pos + l];
33
33
  } else if(header == 0x4e) {
34
- l = _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.fromLEUnsigned(this.buf[this.pos : this.pos + 4]);
34
+ l = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.fromLEUnsigned(this.buf[this.pos : this.pos + 4]);
35
35
  this.pos += 4;
36
36
  ret = this.buf[this.pos : this.pos + l];
37
37
  } else {
@@ -61,6 +61,6 @@ library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ByteStringReader {
61
61
  } else {
62
62
  ret = header;
63
63
  }
64
- return _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.fromLEUnsigned(ret);
64
+ return _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.fromLEUnsigned(ret);
65
65
  }
66
66
  }
@@ -3,7 +3,7 @@ import "stdUtils.scrypt";
3
3
 
4
4
 
5
5
 
6
- library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ByteStringWriter {
6
+ library _opcat_labs_scrypt_ts_opcat_2_1_0__rs__ByteStringWriter {
7
7
  bytes buf;
8
8
  constructor() {
9
9
  this.buf = b'';
@@ -12,13 +12,13 @@ library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ByteStringWriter {
12
12
  int n = len(buf);
13
13
  bytes header = b'';
14
14
  if(n < 0x4c) {
15
- header = _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.toLEUnsigned(n, 1);
15
+ header = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.toLEUnsigned(n, 1);
16
16
  } else if(n < 0x100) {
17
- header = b'4c' + _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.toLEUnsigned(n, 1);
17
+ header = b'4c' + _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.toLEUnsigned(n, 1);
18
18
  } else if(n < 0x10000) {
19
- header = b'4d' + _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.toLEUnsigned(n, 2);
19
+ header = b'4d' + _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.toLEUnsigned(n, 2);
20
20
  } else if(n < 0x100000000) {
21
- header = b'4e' + _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.toLEUnsigned(n, 4);
21
+ header = b'4e' + _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.toLEUnsigned(n, 4);
22
22
  } else {
23
23
  require(false);
24
24
  }
@@ -44,7 +44,7 @@ library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ByteStringWriter {
44
44
  size = 8;
45
45
  this.buf += b'ff';
46
46
  }
47
- this.buf += _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.toLEUnsigned(x, size);
47
+ this.buf += _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.toLEUnsigned(x, size);
48
48
  return true;
49
49
  }
50
50
  }
@@ -5,7 +5,7 @@ import "stdUtils.scrypt";
5
5
 
6
6
 
7
7
 
8
- library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ContextUtils {
8
+ library _opcat_labs_scrypt_ts_opcat_2_1_0__rs__ContextUtils {
9
9
  static const PrivKey privKey = PrivKey(0x26f00fe2340a84335ebdf30f57e9bb58487117b29355718f5e46bf5168d7df97);
10
10
  static const PubKey pubKey = PubKey(b'02ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec0382');
11
11
  static const int invK = 0xc8ffdbaa05d93aa4ede79ec58f06a72562048b775a3507c2bf44bde4f007c40a;
@@ -18,7 +18,7 @@ library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ContextUtils {
18
18
  static function sign(int h, PrivKey privKey, int inverseK, int r, bytes rBigEndian, bytes sigHashType) : Sig {
19
19
  int s = inverseK * (h + r * privKey);
20
20
 
21
- s = _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ContextUtils.normalize(s, 115792089237316195423570985008687907852837564279074904382605163141518161494337);
21
+ s = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__ContextUtils.normalize(s, 115792089237316195423570985008687907852837564279074904382605163141518161494337);
22
22
  if(s > 115792089237316195423570985008687907852837564279074904382605163141518161494337 / 2) {
23
23
  s = 115792089237316195423570985008687907852837564279074904382605163141518161494337 - s;
24
24
  }
@@ -32,13 +32,13 @@ library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ContextUtils {
32
32
  static function fromBEUnsigned(bytes b) : int {
33
33
  return unpack(reverseBytes(b, 32) + b'00');
34
34
  }
35
- static function checkSHPreimage(_opcat_labs_scrypt_ts_opcat_2_0_2__rs__SHPreimage shPreimage, bytes sigHashType) : Sig {
36
- SigHashPreimage preimage = _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ContextUtils.serializeSHPreimage(shPreimage);
35
+ static function checkSHPreimage(_opcat_labs_scrypt_ts_opcat_2_1_0__rs__SHPreimage shPreimage, bytes sigHashType) : Sig {
36
+ SigHashPreimage preimage = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__ContextUtils.serializeSHPreimage(shPreimage);
37
37
  bytes h = hash256(preimage);
38
- Sig sig = _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ContextUtils.sign(_opcat_labs_scrypt_ts_opcat_2_0_2__rs__ContextUtils.fromBEUnsigned(h), _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ContextUtils.privKey, 90914631784428570546048907090666684794265392153046400654824470772421497439242, 7252565254521500021189571868467740368187828957595681190666767817830690399852, _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ContextUtils.rBigEndian, sigHashType);
38
+ Sig sig = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__ContextUtils.sign(_opcat_labs_scrypt_ts_opcat_2_1_0__rs__ContextUtils.fromBEUnsigned(h), _opcat_labs_scrypt_ts_opcat_2_1_0__rs__ContextUtils.privKey, 90914631784428570546048907090666684794265392153046400654824470772421497439242, 7252565254521500021189571868467740368187828957595681190666767817830690399852, _opcat_labs_scrypt_ts_opcat_2_1_0__rs__ContextUtils.rBigEndian, sigHashType);
39
39
  return sig;
40
40
  }
41
- static function serializeSHPreimage(_opcat_labs_scrypt_ts_opcat_2_0_2__rs__SHPreimage shPreimage) : SigHashPreimage {
41
+ static function serializeSHPreimage(_opcat_labs_scrypt_ts_opcat_2_1_0__rs__SHPreimage shPreimage) : SigHashPreimage {
42
42
  require(len(shPreimage.nVersion) == 4);
43
43
  require(len(shPreimage.hashPrevouts) == 32);
44
44
  require(len(shPreimage.spentScriptHash) == 32);
@@ -53,41 +53,41 @@ library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ContextUtils {
53
53
  require(shPreimage.inputIndex >= 0);
54
54
  require(shPreimage.nLockTime >= 0);
55
55
  require(shPreimage.sigHashType == 1 || shPreimage.sigHashType == 2 || shPreimage.sigHashType == 3 || shPreimage.sigHashType == 0x81 || shPreimage.sigHashType == 0x82 || shPreimage.sigHashType == 0x83);
56
- bytes preimage = shPreimage.nVersion + shPreimage.hashPrevouts + shPreimage.spentScriptHash + shPreimage.spentDataHash + _opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxUtils.satoshisToByteString(shPreimage.value) + shPreimage.nSequence + shPreimage.hashSpentAmounts + shPreimage.hashSpentScriptHashes + shPreimage.hashSpentDataHashes + shPreimage.hashSequences + shPreimage.hashOutputs + _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.toLEUnsigned(shPreimage.inputIndex, 4) + _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.toLEUnsigned(shPreimage.nLockTime, 4) + num2bin(shPreimage.sigHashType, 4);
56
+ bytes preimage = shPreimage.nVersion + shPreimage.hashPrevouts + shPreimage.spentScriptHash + shPreimage.spentDataHash + _opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxUtils.satoshisToByteString(shPreimage.value) + shPreimage.nSequence + shPreimage.hashSpentAmounts + shPreimage.hashSpentScriptHashes + shPreimage.hashSpentDataHashes + shPreimage.hashSequences + shPreimage.hashOutputs + _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.toLEUnsigned(shPreimage.inputIndex, 4) + _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.toLEUnsigned(shPreimage.nLockTime, 4) + num2bin(shPreimage.sigHashType, 4);
57
57
  return SigHashPreimage(preimage);
58
58
  }
59
- static function checkPrevouts(bytes prevouts, bytes t_hashPrevouts, int t_inputIndex, int t_inputCount) : _opcat_labs_scrypt_ts_opcat_2_0_2__rs__Outpoint {
59
+ static function checkPrevouts(bytes prevouts, bytes t_hashPrevouts, int t_inputIndex, int t_inputCount) : _opcat_labs_scrypt_ts_opcat_2_1_0__rs__Outpoint {
60
60
  require(hash256(prevouts) == t_hashPrevouts);
61
61
  require(t_inputIndex < t_inputCount);
62
- require(t_inputCount == _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.checkLenDivisibleBy(prevouts, 36));
62
+ require(t_inputCount == _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.checkLenDivisibleBy(prevouts, 36));
63
63
  bytes b = prevouts[t_inputIndex * 36 : (t_inputIndex + 1) * 36];
64
- return {b[0 : 32], _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.byteStringToUInt32(b[32 : 36])};
64
+ return {b[0 : 32], _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.byteStringToUInt32(b[32 : 36])};
65
65
  }
66
66
  static function checkSpentScripts(bytes spentScriptHashes, bytes t_hashSpentScripts, int t_inputCount) : bool {
67
67
  require(hash256(spentScriptHashes) == t_hashSpentScripts);
68
- require(t_inputCount == _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.checkLenDivisibleBy(spentScriptHashes, 32));
68
+ require(t_inputCount == _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.checkLenDivisibleBy(spentScriptHashes, 32));
69
69
  return true;
70
70
  }
71
71
  static function checkSpentAmounts(bytes spentAmounts, bytes hashSpentAmounts) : int {
72
72
  require(hash256(spentAmounts) == hashSpentAmounts);
73
- return _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.checkLenDivisibleBy(spentAmounts, 8);
73
+ return _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.checkLenDivisibleBy(spentAmounts, 8);
74
74
  }
75
75
  static function checkSpentDataHashes(bytes spentDataHashes, bytes hashSpentDataHashes, int inputCount) : bool {
76
76
  require(hash256(spentDataHashes) == hashSpentDataHashes);
77
- require(inputCount == _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.checkLenDivisibleBy(spentDataHashes, 32));
77
+ require(inputCount == _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.checkLenDivisibleBy(spentDataHashes, 32));
78
78
  return true;
79
79
  }
80
80
  static function getSpentScriptHash(bytes spentScriptHashes, int inputIndex) : bytes {
81
81
  return spentScriptHashes[inputIndex * 32 : (inputIndex + 1) * 32];
82
82
  }
83
83
  static function getSpentAmount(bytes spentAmounts, int inputIndex) : int {
84
- return _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.fromLEUnsigned(spentAmounts[inputIndex * 8 : (inputIndex + 1) * 8]);
84
+ return _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.fromLEUnsigned(spentAmounts[inputIndex * 8 : (inputIndex + 1) * 8]);
85
85
  }
86
86
  static function getSpentDataHash(bytes spentDataHashes, int inputIndex) : bytes {
87
87
  return spentDataHashes[inputIndex * 32 : (inputIndex + 1) * 32];
88
88
  }
89
- static function checknLockTime(_opcat_labs_scrypt_ts_opcat_2_0_2__rs__SHPreimage shPreimage, int nlockTime) : bool {
90
- int nSequence = _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.fromLEUnsigned(shPreimage.nSequence);
89
+ static function checknLockTime(_opcat_labs_scrypt_ts_opcat_2_1_0__rs__SHPreimage shPreimage, int nlockTime) : bool {
90
+ int nSequence = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.fromLEUnsigned(shPreimage.nSequence);
91
91
  return (nSequence < 4294967295 && (nlockTime < 500000000 ? shPreimage.nLockTime < 500000000 : true) && shPreimage.nLockTime >= nlockTime);
92
92
  }
93
93
  }
@@ -0,0 +1,44 @@
1
+ import "../types/structs.scrypt";
2
+ import "txUtils.scrypt";
3
+ import "contextUtils.scrypt";
4
+ import "txUtils.scrypt";
5
+ import "../types/structs.scrypt";
6
+ import "contextUtils.scrypt";
7
+
8
+
9
+
10
+
11
+ contract _opcat_labs_scrypt_ts_opcat_2_1_0__rs__Genesis {
12
+ constructor() {
13
+ }
14
+ public function checkDeploy(_opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxOut[6] outputs, int outputCount, _opcat_labs_scrypt_ts_opcat_2_1_0__rs__SHPreimage __scrypt_ts_shPreimage, bytes __scrypt_ts_spentAmounts, bytes __scrypt_ts_spentScriptHashes) {
15
+ require(Tx.checkPreimageSigHashType(_opcat_labs_scrypt_ts_opcat_2_1_0__rs__ContextUtils.serializeSHPreimage(__scrypt_ts_shPreimage), SigHash.ALL));
16
+
17
+ int __scrypt_ts_inputCount = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__ContextUtils.checkSpentAmounts(__scrypt_ts_spentAmounts, __scrypt_ts_shPreimage.hashSpentAmounts);
18
+
19
+ _opcat_labs_scrypt_ts_opcat_2_1_0__rs__ContextUtils.checkSpentScripts(__scrypt_ts_spentScriptHashes, __scrypt_ts_shPreimage.hashSpentScriptHashes, __scrypt_ts_inputCount);
20
+
21
+ require(__scrypt_ts_shPreimage.inputIndex == 0);
22
+ require(__scrypt_ts_inputCount <= (6));
23
+ require(outputCount > 0 && outputCount <= (6));
24
+ bytes output0ScriptHash = outputs[0].scriptHash;
25
+ bytes outputBytes = b'';
26
+ loop (6) : index {
27
+ _opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxOut _output = outputs[index];
28
+ if(index < outputCount) {
29
+ require(len(_output.scriptHash) > 0);
30
+ outputBytes += _opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxUtils.buildDataOutput(_output.scriptHash, _output.satoshis, _output.dataHash);
31
+ if(index > 0) {
32
+ require(output0ScriptHash != _output.scriptHash);
33
+ }
34
+ }
35
+ }
36
+ loop (6) : index {
37
+ if(index < __scrypt_ts_inputCount) {
38
+ bytes inputScriptHash = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__ContextUtils.getSpentScriptHash(__scrypt_ts_spentScriptHashes, (index));
39
+ require(output0ScriptHash != inputScriptHash);
40
+ }
41
+ }
42
+ require(hash256(outputBytes) == __scrypt_ts_shPreimage.hashOutputs);
43
+ }
44
+ }
@@ -1,7 +1,10 @@
1
+ import "txUtils.scrypt";
2
+ import "contextUtils.scrypt";
1
3
 
2
4
 
3
5
 
4
- contract _opcat_labs_scrypt_ts_opcat_2_0_2__rs__P2PK {
6
+
7
+ contract _opcat_labs_scrypt_ts_opcat_2_1_0__rs__P2PK {
5
8
  const PubKey pubKey;
6
9
  public function unlock(Sig sig) {
7
10
  require(checkSig(sig, this.pubKey));
@@ -1,7 +1,10 @@
1
+ import "txUtils.scrypt";
2
+ import "contextUtils.scrypt";
1
3
 
2
4
 
3
5
 
4
- contract _opcat_labs_scrypt_ts_opcat_2_0_2__rs__P2PKH {
6
+
7
+ contract _opcat_labs_scrypt_ts_opcat_2_1_0__rs__P2PKH {
5
8
  const Ripemd160 addr;
6
9
  public function unlock(Sig sig, PubKey pubkey) {
7
10
  require(hash160(pubkey) == this.addr);
@@ -1,5 +1,5 @@
1
1
 
2
2
 
3
3
 
4
- library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StateLib {
4
+ library _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StateLib {
5
5
  }
@@ -1,7 +1,7 @@
1
1
 
2
2
 
3
3
 
4
- library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StateUtils {
4
+ library _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StateUtils {
5
5
  static function checkInputState(int t_inputIndex, bytes stateHash, bytes t_spentDataHashes) : bool {
6
6
  require(t_spentDataHashes[t_inputIndex * 32 : (t_inputIndex + 1) * 32] == stateHash);
7
7
  return true;
@@ -1,12 +1,12 @@
1
1
 
2
2
 
3
3
 
4
- struct _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ReadVarintResult {
4
+ struct _opcat_labs_scrypt_ts_opcat_2_1_0__rs__ReadVarintResult {
5
5
  bytes data;
6
6
  int nextPos;
7
7
  }
8
8
 
9
- library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils {
9
+ library _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils {
10
10
  static function checkLenDivisibleBy(bytes b, int n) : int {
11
11
  int l = len(b);
12
12
  require(l % n == 0);
@@ -14,15 +14,15 @@ library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils {
14
14
  }
15
15
  static function uint64ToByteString(int n) : bytes {
16
16
  require(n >= 0 && n <= 18446744073709551615);
17
- return _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.toLEUnsigned(n, 8);
17
+ return _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.toLEUnsigned(n, 8);
18
18
  }
19
19
  static function uint32ToByteString(int n) : bytes {
20
20
  require(n >= 0 && n <= 4294967295);
21
- return _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.toLEUnsigned(n, 4);
21
+ return _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.toLEUnsigned(n, 4);
22
22
  }
23
23
  static function byteStringToUInt32(bytes b) : int {
24
24
  require(len(b) == 4);
25
- return _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.fromLEUnsigned(b);
25
+ return _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.fromLEUnsigned(b);
26
26
  }
27
27
  static function toLEUnsigned(int n, int l) : bytes {
28
28
  bytes m = num2bin(n, l + 1);
@@ -46,7 +46,7 @@ library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils {
46
46
  b = b'ff';
47
47
  size = 8;
48
48
  }
49
- return b + _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.toLEUnsigned(n, size);
49
+ return b + _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.toLEUnsigned(n, size);
50
50
  }
51
51
  static function pushData(bytes buf) : bytes {
52
52
  int n = len(buf);
@@ -67,27 +67,27 @@ library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils {
67
67
  } else {
68
68
  require(false);
69
69
  }
70
- return header + _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.toLEUnsigned(n, size);
70
+ return header + _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.toLEUnsigned(n, size);
71
71
  }
72
- static function readVarint(bytes buf, int pos) : _opcat_labs_scrypt_ts_opcat_2_0_2__rs__ReadVarintResult {
72
+ static function readVarint(bytes buf, int pos) : _opcat_labs_scrypt_ts_opcat_2_1_0__rs__ReadVarintResult {
73
73
  int l = 0;
74
74
  bytes ret = b'';
75
75
  int nextPos = pos;
76
76
  bytes header = buf[pos : pos + 1];
77
77
  if(header == b'fd') {
78
- l = _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.fromLEUnsigned(buf[pos + 1 : pos + 3]);
78
+ l = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.fromLEUnsigned(buf[pos + 1 : pos + 3]);
79
79
  ret = buf[3 : 3 + l];
80
80
  nextPos = pos + 3 + l;
81
81
  } else if(header == b'fe') {
82
- l = _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.fromLEUnsigned(buf[pos + 1 : pos + 5]);
82
+ l = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.fromLEUnsigned(buf[pos + 1 : pos + 5]);
83
83
  ret = buf[pos + 5 : pos + 5 + l];
84
84
  nextPos = pos + 5 + l;
85
85
  } else if(header == b'ff') {
86
- l = _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.fromLEUnsigned(buf[pos + 1 : pos + 9]);
86
+ l = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.fromLEUnsigned(buf[pos + 1 : pos + 9]);
87
87
  ret = buf[pos + 9 : pos + 9 + l];
88
88
  nextPos = pos + 9 + l;
89
89
  } else {
90
- l = _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.fromLEUnsigned(buf[pos : pos + 1]);
90
+ l = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.fromLEUnsigned(buf[pos : pos + 1]);
91
91
  ret = buf[pos + 1 : pos + 1 + l];
92
92
  nextPos = pos + 1 + l;
93
93
  }
@@ -4,17 +4,17 @@ import "stdUtils.scrypt";
4
4
 
5
5
 
6
6
 
7
- library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxHashPreimageUtils {
8
- static function getTxHashFromTxHashPreimage(_opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxHashPreimage txHashPreimage) : bytes {
7
+ library _opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxHashPreimageUtils {
8
+ static function getTxHashFromTxHashPreimage(_opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxHashPreimage txHashPreimage) : bytes {
9
9
  require(len(txHashPreimage.version) == 4);
10
- int inputCount = _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.checkLenDivisibleBy(txHashPreimage.inputList, 72);
11
- int outputCount = _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.checkLenDivisibleBy(txHashPreimage.outputList, 72);
12
- return hash256(txHashPreimage.version + _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.writeVarInt(inputCount) + txHashPreimage.inputList + _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.writeVarInt(outputCount) + txHashPreimage.outputList + txHashPreimage.nLockTime);
10
+ int inputCount = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.checkLenDivisibleBy(txHashPreimage.inputList, 72);
11
+ int outputCount = _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.checkLenDivisibleBy(txHashPreimage.outputList, 72);
12
+ return hash256(txHashPreimage.version + _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.writeVarInt(inputCount) + txHashPreimage.inputList + _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.writeVarInt(outputCount) + txHashPreimage.outputList + txHashPreimage.nLockTime);
13
13
  }
14
- static function getInputByteString(_opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxHashPreimage txHashPreimage, int inputIndex) : bytes {
14
+ static function getInputByteString(_opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxHashPreimage txHashPreimage, int inputIndex) : bytes {
15
15
  return txHashPreimage.inputList[inputIndex * 72 : (inputIndex + 1) * 72];
16
16
  }
17
- static function getOutputByteString(_opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxHashPreimage txHashPreimage, int outputIndex) : bytes {
17
+ static function getOutputByteString(_opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxHashPreimage txHashPreimage, int outputIndex) : bytes {
18
18
  return txHashPreimage.outputList[outputIndex * 72 : (outputIndex + 1) * 72];
19
19
  }
20
20
  }
@@ -4,10 +4,10 @@ import "stdUtils.scrypt";
4
4
 
5
5
 
6
6
 
7
- library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxUtils {
7
+ library _opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxUtils {
8
8
  static const int ZERO_SATS = 0;
9
9
  static function buildOutput(bytes scriptHash, int satoshis) : bytes {
10
- return _opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxUtils.buildDataOutput(scriptHash, satoshis, sha256(b''));
10
+ return _opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxUtils.buildDataOutput(scriptHash, satoshis, sha256(b''));
11
11
  }
12
12
  static function buildDataOutput(bytes scriptHash, int satoshis, bytes dataHash) : bytes {
13
13
  int scriptHashLen = len(scriptHash);
@@ -15,34 +15,34 @@ library _opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxUtils {
15
15
  require(scriptHashLen == 32);
16
16
  require(dataHashLen == 32);
17
17
  require(satoshis >= 0);
18
- return _opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxUtils.satoshisToByteString(satoshis) + scriptHash + dataHash;
18
+ return _opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxUtils.satoshisToByteString(satoshis) + scriptHash + dataHash;
19
19
  }
20
- static function buildChangeOutput(_opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxOut change) : bytes {
21
- return change.satoshis > 0 ? _opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxUtils.buildDataOutput(change.scriptHash, change.satoshis, change.dataHash) : b'';
20
+ static function buildChangeOutput(_opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxOut change) : bytes {
21
+ return change.satoshis > 0 ? _opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxUtils.buildDataOutput(change.scriptHash, change.satoshis, change.dataHash) : b'';
22
22
  }
23
- static function mergeInput(_opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxIn txInput) : bytes {
23
+ static function mergeInput(_opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxIn txInput) : bytes {
24
24
  require(len(txInput.prevTxHash) == 32);
25
25
  require(len(txInput.scriptHash) == 32);
26
- return (txInput.prevTxHash + _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.uint32ToByteString(txInput.prevOutputIndex) + txInput.scriptHash + _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.uint32ToByteString(txInput.sequence));
26
+ return (txInput.prevTxHash + _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.uint32ToByteString(txInput.prevOutputIndex) + txInput.scriptHash + _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.uint32ToByteString(txInput.sequence));
27
27
  }
28
28
  static function buildOpReturnOutput(bytes data) : bytes {
29
29
  bytes script = b'6a' + pack(len(data)) + data;
30
- return _opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxUtils.satoshisToByteString(0) + sha256(script) + sha256(b'');
30
+ return _opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxUtils.satoshisToByteString(0) + sha256(script) + sha256(b'');
31
31
  }
32
32
  static function buildP2PKHScript(Ripemd160 addr) : bytes {
33
33
  return (OpCode.OP_DUP + OpCode.OP_HASH160 + pack(20) + addr + OpCode.OP_EQUALVERIFY + OpCode.OP_CHECKSIG);
34
34
  }
35
35
  static function buildP2PKHOutput(int amount, Ripemd160 addr) : bytes {
36
- return _opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxUtils.buildDataOutput(sha256(_opcat_labs_scrypt_ts_opcat_2_0_2__rs__TxUtils.buildP2PKHScript(addr)), amount, sha256(b''));
36
+ return _opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxUtils.buildDataOutput(sha256(_opcat_labs_scrypt_ts_opcat_2_1_0__rs__TxUtils.buildP2PKHScript(addr)), amount, sha256(b''));
37
37
  }
38
38
  static function buildOpreturnScript(bytes data) : bytes {
39
- return OpCode.OP_FALSE + OpCode.OP_RETURN + _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.pushData(data);
39
+ return OpCode.OP_FALSE + OpCode.OP_RETURN + _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.pushData(data);
40
40
  }
41
41
  static function satoshisToByteString(int n) : bytes {
42
- return _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.uint64ToByteString(n);
42
+ return _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.uint64ToByteString(n);
43
43
  }
44
44
  static function byteStringToSatoshis(bytes bs) : int {
45
45
  require(len(bs) == 8);
46
- return _opcat_labs_scrypt_ts_opcat_2_0_2__rs__StdUtils.fromLEUnsigned(bs);
46
+ return _opcat_labs_scrypt_ts_opcat_2_1_0__rs__StdUtils.fromLEUnsigned(bs);
47
47
  }
48
48
  }