cashscript 0.11.4 → 0.11.5
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/dist/Transaction.js +1 -2
- package/dist/TransactionBuilder.js +1 -2
- package/dist/debugging.js +11 -3
- package/dist/types/type-inference.d.ts +8 -6
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +3 -23
- package/package.json +3 -5
package/dist/Transaction.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { hexToBin, decodeTransaction, } from '@bitauth/libauth';
|
|
2
|
-
import delay from 'delay';
|
|
3
2
|
import { encodeBip68, placeholder, } from '@cashscript/utils';
|
|
4
3
|
import deepEqual from 'fast-deep-equal';
|
|
5
4
|
import { isUtxoP2PKH, SignatureAlgorithm, } from './interfaces.js';
|
|
6
|
-
import { createInputScript, getInputSize, createOpReturnOutput, getTxSizeWithoutInputs, validateOutput, utxoComparator, calculateDust, getOutputSize, utxoTokenComparator, } from './utils.js';
|
|
5
|
+
import { createInputScript, getInputSize, createOpReturnOutput, getTxSizeWithoutInputs, validateOutput, utxoComparator, calculateDust, getOutputSize, utxoTokenComparator, delay, } from './utils.js';
|
|
7
6
|
import SignatureTemplate from './SignatureTemplate.js';
|
|
8
7
|
import { P2PKH_INPUT_SIZE } from './constants.js';
|
|
9
8
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { binToHex, decodeTransaction, decodeTransactionUnsafe, encodeTransaction, hexToBin, } from '@bitauth/libauth';
|
|
2
|
-
import delay from 'delay';
|
|
3
2
|
import { isUnlockableUtxo, isStandardUnlockableUtxo, isP2PKHUnlocker, } from './interfaces.js';
|
|
4
|
-
import { cashScriptOutputToLibauthOutput, createOpReturnOutput, generateLibauthSourceOutputs, validateInput, validateOutput, } from './utils.js';
|
|
3
|
+
import { cashScriptOutputToLibauthOutput, createOpReturnOutput, delay, generateLibauthSourceOutputs, validateInput, validateOutput, } from './utils.js';
|
|
5
4
|
import { FailedTransactionError } from './Errors.js';
|
|
6
5
|
import { getBitauthUri } from './LibauthTemplate.js';
|
|
7
6
|
import { debugLibauthTemplate, getLibauthTemplates } from './advanced/LibauthTemplate.js';
|
package/dist/debugging.js
CHANGED
|
@@ -41,7 +41,8 @@ const debugSingleScenario = (template, artifact, unlockingScriptId, scenarioId)
|
|
|
41
41
|
const executedLogs = (artifact.debug?.logs ?? [])
|
|
42
42
|
.filter((log) => executedDebugSteps.some((debugStep) => log.ip === debugStep.ip));
|
|
43
43
|
for (const log of executedLogs) {
|
|
44
|
-
|
|
44
|
+
const inputIndex = extractInputIndexFromScenario(scenarioId);
|
|
45
|
+
logConsoleLogStatement(log, executedDebugSteps, artifact, inputIndex);
|
|
45
46
|
}
|
|
46
47
|
const lastExecutedDebugStep = executedDebugSteps[executedDebugSteps.length - 1];
|
|
47
48
|
// If an error is present in the last step, that means a require statement in the middle of the function failed
|
|
@@ -91,6 +92,13 @@ const debugSingleScenario = (template, artifact, unlockingScriptId, scenarioId)
|
|
|
91
92
|
}
|
|
92
93
|
return fullDebugSteps;
|
|
93
94
|
};
|
|
95
|
+
// Note: this relies on the naming convention that the scenario ID is of the form <name>_input<index>_evaluate
|
|
96
|
+
const extractInputIndexFromScenario = (scenarioId) => {
|
|
97
|
+
const match = scenarioId.match(/_input(\d+)_/);
|
|
98
|
+
if (!match)
|
|
99
|
+
throw new Error(`Invalid scenario ID: ${scenarioId}`);
|
|
100
|
+
return parseInt(match[1]);
|
|
101
|
+
};
|
|
94
102
|
// internal util. instantiates the virtual machine and compiles the template into a program
|
|
95
103
|
const createProgram = (template, unlockingScriptId, scenarioId) => {
|
|
96
104
|
const configuration = walletTemplateToCompilerConfiguration(template);
|
|
@@ -115,7 +123,7 @@ const createProgram = (template, unlockingScriptId, scenarioId) => {
|
|
|
115
123
|
}
|
|
116
124
|
return { vm, program: scenarioGeneration.scenario.program };
|
|
117
125
|
};
|
|
118
|
-
const logConsoleLogStatement = (log, debugSteps, artifact) => {
|
|
126
|
+
const logConsoleLogStatement = (log, debugSteps, artifact, inputIndex) => {
|
|
119
127
|
let line = `${artifact.contractName}.cash:${log.line}`;
|
|
120
128
|
const decodedData = log.data.map((element) => {
|
|
121
129
|
if (typeof element === 'string')
|
|
@@ -124,7 +132,7 @@ const logConsoleLogStatement = (log, debugSteps, artifact) => {
|
|
|
124
132
|
const transformedDebugStep = applyStackItemTransformations(element, debugStep);
|
|
125
133
|
return decodeStackItem(element, transformedDebugStep.stack);
|
|
126
134
|
});
|
|
127
|
-
console.log(
|
|
135
|
+
console.log(`[Input #${inputIndex}] ${line} ${decodedData.join(' ')}`);
|
|
128
136
|
};
|
|
129
137
|
const applyStackItemTransformations = (element, debugStep) => {
|
|
130
138
|
if (!element.transformations)
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import type SignatureTemplate from '../SignatureTemplate.js';
|
|
2
|
+
type BytesType = Uint8Array | string;
|
|
3
|
+
type SignatureType = SignatureTemplate | BytesType;
|
|
2
4
|
type TypeMap = {
|
|
3
|
-
[k: `bytes${number}`]:
|
|
5
|
+
[k: `bytes${number}`]: BytesType;
|
|
4
6
|
} & {
|
|
5
|
-
byte:
|
|
6
|
-
bytes:
|
|
7
|
+
byte: BytesType;
|
|
8
|
+
bytes: BytesType;
|
|
7
9
|
bool: boolean;
|
|
8
10
|
int: bigint;
|
|
9
11
|
string: string;
|
|
10
|
-
pubkey:
|
|
11
|
-
sig:
|
|
12
|
-
datasig:
|
|
12
|
+
pubkey: BytesType;
|
|
13
|
+
sig: SignatureType;
|
|
14
|
+
datasig: BytesType;
|
|
13
15
|
};
|
|
14
16
|
type ProcessParam<Param> = Param extends {
|
|
15
17
|
type: infer Type;
|
package/dist/utils.d.ts
CHANGED
|
@@ -38,3 +38,4 @@ export declare const extendedStringify: (obj: any, spaces?: number) => string;
|
|
|
38
38
|
export declare const zip: <T, U>(a: readonly T[], b: readonly U[]) => [T, U][];
|
|
39
39
|
export declare const isFungibleTokenUtxo: (utxo: Utxo) => boolean;
|
|
40
40
|
export declare const isNonTokenUtxo: (utxo: Utxo) => boolean;
|
|
41
|
+
export declare const delay: (ms: number) => Promise<void>;
|
package/dist/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { cashAddressToLockingBytecode, decodeCashAddress, addressContentsToLockingBytecode, lockingBytecodeToCashAddress, binToHex, generateSigningSerializationBch, utf8ToBin, hexToBin,
|
|
2
|
-
import { encodeInt, hash160, hash256, sha256, Op, scriptToBytecode, } from '@cashscript/utils';
|
|
1
|
+
import { cashAddressToLockingBytecode, decodeCashAddress, addressContentsToLockingBytecode, lockingBytecodeToCashAddress, binToHex, generateSigningSerializationBch, utf8ToBin, hexToBin, LockingBytecodeType, encodeTransactionOutput, isHex, bigIntToCompactUint, NonFungibleTokenCapability, bigIntToVmNumber, } from '@bitauth/libauth';
|
|
2
|
+
import { encodeInt, hash160, hash256, sha256, Op, scriptToBytecode, encodeNullDataScript, } from '@cashscript/utils';
|
|
3
3
|
import { Network, } from './interfaces.js';
|
|
4
4
|
import { VERSION_SIZE, LOCKTIME_SIZE } from './constants.js';
|
|
5
5
|
import { OutputSatoshisTooSmallError, OutputTokenAmountTooSmallError, TokensToNonTokenAddressError, UndefinedInputError, } from './Errors.js';
|
|
@@ -220,27 +220,6 @@ export function getNetworkPrefix(network) {
|
|
|
220
220
|
return 'bitcoincash';
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
|
-
// ////////////////////////////////////////////////////////////////////////////
|
|
224
|
-
// For encoding OP_RETURN data (doesn't require BIP62.3 / MINIMALDATA)
|
|
225
|
-
function encodeNullDataScript(chunks) {
|
|
226
|
-
return flattenBinArray(chunks.map((chunk) => {
|
|
227
|
-
if (typeof chunk === 'number') {
|
|
228
|
-
return new Uint8Array([chunk]);
|
|
229
|
-
}
|
|
230
|
-
const pushdataOpcode = getPushDataOpcode(chunk);
|
|
231
|
-
return new Uint8Array([...pushdataOpcode, ...chunk]);
|
|
232
|
-
}));
|
|
233
|
-
}
|
|
234
|
-
function getPushDataOpcode(data) {
|
|
235
|
-
const { byteLength } = data;
|
|
236
|
-
if (byteLength === 0)
|
|
237
|
-
return Uint8Array.from([0x4c, 0x00]);
|
|
238
|
-
if (byteLength < 76)
|
|
239
|
-
return Uint8Array.from([byteLength]);
|
|
240
|
-
if (byteLength < 256)
|
|
241
|
-
return Uint8Array.from([0x4c, byteLength]);
|
|
242
|
-
throw new Error('Pushdata too large');
|
|
243
|
-
}
|
|
244
223
|
const randomInt = () => BigInt(Math.floor(Math.random() * 10000));
|
|
245
224
|
export const randomUtxo = (defaults) => ({
|
|
246
225
|
...{
|
|
@@ -290,4 +269,5 @@ export const extendedStringify = (obj, spaces) => JSON.stringify(obj, (_, v) =>
|
|
|
290
269
|
export const zip = (a, b) => (Array.from(Array(Math.max(b.length, a.length)), (_, i) => [a[i], b[i]]));
|
|
291
270
|
export const isFungibleTokenUtxo = (utxo) => (utxo.token !== undefined && utxo.token.amount > 0n && utxo.token.nft === undefined);
|
|
292
271
|
export const isNonTokenUtxo = (utxo) => utxo.token === undefined;
|
|
272
|
+
export const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
293
273
|
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cashscript",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.5",
|
|
4
4
|
"description": "Easily write and interact with Bitcoin Cash contracts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bitcoin cash",
|
|
@@ -46,11 +46,9 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@bitauth/libauth": "^3.1.0-next.2",
|
|
49
|
-
"@cashscript/utils": "^0.11.
|
|
49
|
+
"@cashscript/utils": "^0.11.5",
|
|
50
50
|
"@electrum-cash/network": "^4.1.3",
|
|
51
51
|
"@mr-zwets/bchn-api-wrapper": "^1.0.1",
|
|
52
|
-
"@types/node": "^22.17.0",
|
|
53
|
-
"delay": "^6.0.0",
|
|
54
52
|
"fast-deep-equal": "^3.1.3",
|
|
55
53
|
"pako": "^2.1.0",
|
|
56
54
|
"semver": "^7.7.2"
|
|
@@ -64,5 +62,5 @@
|
|
|
64
62
|
"jest": "^29.7.0",
|
|
65
63
|
"typescript": "^5.9.2"
|
|
66
64
|
},
|
|
67
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "0ccda722dde4c0825285f3a6aa05898a8f62c160"
|
|
68
66
|
}
|