cashscript 0.13.0-next.8 → 0.13.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/dist/Contract.js CHANGED
@@ -92,10 +92,10 @@ class ContractInternal extends ContractBase {
92
92
  if (abiFunction.inputs.length !== args.length) {
93
93
  throw new Error(`Incorrect number of arguments passed to function ${abiFunction.name}. Expected ${abiFunction.inputs.length} arguments (${abiFunction.inputs.map((input) => input.type)}) but got ${args.length}`);
94
94
  }
95
- const bytecode = hexToBin(this.bytecode);
96
95
  const encodedArgs = args
97
96
  .map((arg, i) => encodeFunctionArgument(arg, abiFunction.inputs[i].type));
98
97
  const generateUnlockingBytecode = ({ transaction, sourceOutputs, inputIndex }) => {
98
+ const bytecode = hexToBin(this.bytecode);
99
99
  const completeArgs = encodedArgs.map((arg) => {
100
100
  if (!(arg instanceof SignatureTemplate))
101
101
  return arg;
@@ -104,10 +104,10 @@ class ContractInternal extends ContractBase {
104
104
  const sighash = hash256(preimage);
105
105
  return arg.generateSignature(sighash);
106
106
  });
107
- const unlockingBytecode = createUnlockingBytecode(this.contractType, hexToBin(this.bytecode), completeArgs, selector);
107
+ const unlockingBytecode = createUnlockingBytecode(this.contractType, bytecode, completeArgs, selector);
108
108
  return unlockingBytecode;
109
109
  };
110
- const generateLockingBytecode = () => addressToLockScript(this.address);
110
+ const generateLockingBytecode = () => hexToBin(this.lockingBytecode);
111
111
  return { generateUnlockingBytecode, generateLockingBytecode, contract: this, params: args, abiFunction };
112
112
  };
113
113
  }
package/dist/Errors.js CHANGED
@@ -82,7 +82,10 @@ export class FailedRequireError extends FailedTransactionError {
82
82
  const { statement, lineNumber } = getLocationDataForInstructionPointer(artifact, failingInstructionPointer);
83
83
  const baseMessage = `${artifact.contractName}.cash:${lineNumber} Require statement failed at input ${inputIndex} in contract ${artifact.contractName}.cash at line ${lineNumber}`;
84
84
  const baseMessageWithRequireMessage = `${baseMessage} with the following message: ${requireStatement.message}`;
85
- const fullMessage = `${requireStatement.message ? baseMessageWithRequireMessage : baseMessage}.\nFailing statement: ${statement}`;
85
+ const headline = `${requireStatement.message ? baseMessageWithRequireMessage : baseMessage}.`;
86
+ // Compiler-injected guards (e.g. the tx.locktime guard) have no user-written source, so the
87
+ // extracted statement is empty — the require message fully describes the failure on its own.
88
+ const fullMessage = statement.trim() ? `${headline}\nFailing statement: ${statement}` : headline;
86
89
  super(fullMessage, bitauthUri);
87
90
  this.artifact = artifact;
88
91
  this.failingInstructionPointer = failingInstructionPointer;
@@ -360,14 +360,15 @@ export class TransactionBuilder {
360
360
  }
361
361
  catch (e) {
362
362
  const reason = e.error ?? e.message;
363
- try {
364
- const bitauthUri = getBitauthUri(this.getLibauthTemplate());
365
- throw new FailedTransactionError(reason, bitauthUri);
366
- }
367
- catch {
368
- // Preserve the original broadcast failure reason if URI generation fails
369
- throw new FailedTransactionError(reason, 'Bitauth URI generation failed');
370
- }
363
+ const getBitauthUriWithFallback = () => {
364
+ try {
365
+ return getBitauthUri(this.getLibauthTemplate());
366
+ }
367
+ catch {
368
+ return 'Bitauth URI generation failed';
369
+ }
370
+ };
371
+ throw new FailedTransactionError(reason, getBitauthUriWithFallback());
371
372
  }
372
373
  }
373
374
  async getTxDetails(txid, raw) {
@@ -73,8 +73,7 @@ const generateLockingBytecodeParamsMapping = (transactionBuilder) => {
73
73
  if (isContractUnlocker(input.unlocker)) {
74
74
  const lockScriptName = getLockScriptName(input.unlocker.contract);
75
75
  const lockingScriptParams = generateLockingScriptParams(input.unlocker.contract, input, lockScriptName);
76
- const lockingBytecode = binToHex(addressToLockScript(input.unlocker.contract.address));
77
- mapping[lockingBytecode] = lockingScriptParams;
76
+ mapping[input.unlocker.contract.lockingBytecode] = lockingScriptParams;
78
77
  }
79
78
  }
80
79
  return mapping;
@@ -394,7 +393,7 @@ const generateTemplateScenarioTransactionOutputLockingBytecode = (csOutput, liba
394
393
  return lockingBytecodeParams;
395
394
  if (csOutput.to instanceof Uint8Array)
396
395
  return binToHex(csOutput.to);
397
- if (contract && [contract.address, contract.tokenAddress].includes(csOutput.to))
396
+ if (contract && contract.contractType !== 'p2s' && [contract.address, contract.tokenAddress].includes(csOutput.to))
398
397
  return {};
399
398
  return binToHex(addressToLockScript(csOutput.to));
400
399
  };
@@ -1,10 +1,13 @@
1
- import { bytecodeToScript, formatBitAuthScript } from '@cashscript/utils';
1
+ import { bytecodeToScript, formatBitAuthScript, sha256 } from '@cashscript/utils';
2
2
  import { HashType, SignatureAlgorithm, VmTarget } from '../interfaces.js';
3
3
  import { hexToBin, binToHex, isHex, decodeCashAddress, assertSuccess, decodeAuthenticationInstructions } from '@bitauth/libauth';
4
4
  import { zip } from '../utils.js';
5
5
  import SignatureTemplate from '../SignatureTemplate.js';
6
6
  export const DEFAULT_VM_TARGET = VmTarget.BCH_2026_05;
7
7
  export const getLockScriptName = (contract) => {
8
+ if (contract.contractType === 'p2s') {
9
+ return `${contract.artifact.contractName}_${binToHex(sha256(hexToBin(contract.lockingBytecode)))}_lock`;
10
+ }
8
11
  const result = decodeCashAddress(contract.address);
9
12
  if (typeof result === 'string')
10
13
  throw new Error(result);
@@ -56,3 +56,6 @@ export default class MockNetworkProvider implements NetworkProvider {
56
56
  */
57
57
  reset(): void;
58
58
  }
59
+ export declare class FailingMockNetworkProvider extends MockNetworkProvider {
60
+ sendRawTransaction(_txHex: string): Promise<string>;
61
+ }
@@ -98,4 +98,9 @@ export default class MockNetworkProvider {
98
98
  this.transactionMap = {};
99
99
  }
100
100
  }
101
+ export class FailingMockNetworkProvider extends MockNetworkProvider {
102
+ async sendRawTransaction(_txHex) {
103
+ throw new Error('broadcast failed');
104
+ }
105
+ }
101
106
  //# sourceMappingURL=MockNetworkProvider.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cashscript",
3
- "version": "0.13.0-next.8",
3
+ "version": "0.13.0",
4
4
  "description": "Easily write and interact with Bitcoin Cash contracts",
5
5
  "keywords": [
6
6
  "bitcoin cash",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@bitauth/libauth": "^3.1.0-next.8",
45
- "@cashscript/utils": "^0.13.0-next.8",
45
+ "@cashscript/utils": "^0.13.0",
46
46
  "@electrum-cash/network": "^4.1.3",
47
47
  "fflate": "^0.8.2",
48
48
  "semver": "^7.7.2"
@@ -56,5 +56,5 @@
56
56
  "typescript": "^5.9.2",
57
57
  "vitest": "^4.0.15"
58
58
  },
59
- "gitHead": "579998062f2f9c52393568b09b580407228cb79f"
59
+ "gitHead": "a3461662016a2f3dad36431ba5a2b148bcc4dc75"
60
60
  }