Skip to content

Commit 8a3e801

Browse files
committed
Final changes before 0.12 release
- Rename bitauthUri to getBitauthUri and update docs for it - Move around some utils - Add getVmResourceUsage to release notes and docs - Update docs for MockNetworkProvider default changes
1 parent 20080f5 commit 8a3e801

File tree

15 files changed

+78
-39
lines changed

15 files changed

+78
-39
lines changed

packages/cashscript/src/TransactionBuilder.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ export class TransactionBuilder {
247247
return vmResourceUsage;
248248
}
249249

250-
// TODO: rename to getBitauthUri()
251-
bitauthUri(): string {
250+
getBitauthUri(): string {
252251
console.warn('WARNING: it is unsafe to use this Bitauth URI when using real private keys as they are included in the transaction template');
253252
return getBitauthUri(this.getLibauthTemplate());
254253
}
@@ -273,7 +272,7 @@ export class TransactionBuilder {
273272
return raw ? await this.getTxDetails(txid, raw) : await this.getTxDetails(txid);
274273
} catch (e: any) {
275274
const reason = e.error ?? e.message;
276-
throw new FailedTransactionError(reason, this.bitauthUri());
275+
throw new FailedTransactionError(reason, this.getBitauthUri());
277276
}
278277
}
279278

packages/cashscript/src/libauth-template/LibauthTemplate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ import {
3131
VmTarget,
3232
} from '../interfaces.js';
3333
import SignatureTemplate from '../SignatureTemplate.js';
34-
import { addressToLockScript, extendedStringify, getSignatureAndPubkeyFromP2PKHInput, zip } from '../utils.js';
34+
import { addressToLockScript, extendedStringify, zip } from '../utils.js';
3535
import { TransactionBuilder } from '../TransactionBuilder.js';
3636
import { deflate } from 'pako';
3737
import MockNetworkProvider from '../network/MockNetworkProvider.js';
38-
import { addHexPrefixExceptEmpty, formatBytecodeForDebugging, formatParametersForDebugging, getLockScriptName, getUnlockScriptName, lockingBytecodeIsSetToSlot, serialiseTokenDetails } from './utils.js';
38+
import { addHexPrefixExceptEmpty, formatBytecodeForDebugging, formatParametersForDebugging, getLockScriptName, getSignatureAndPubkeyFromP2PKHInput, getUnlockScriptName, lockingBytecodeIsSetToSlot, serialiseTokenDetails } from './utils.js';
3939

4040
// TODO: Add / improve descriptions throughout the template generation
4141

packages/cashscript/src/libauth-template/utils.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AbiFunction, AbiInput, Artifact, bytecodeToScript, formatBitAuthScript } from '@cashscript/utils';
22
import { HashType, LibauthTokenDetails, SignatureAlgorithm, TokenDetails } from '../interfaces.js';
3-
import { hexToBin, binToHex, isHex, decodeCashAddress, type WalletTemplateScenarioBytecode } from '@bitauth/libauth';
3+
import { hexToBin, binToHex, isHex, decodeCashAddress, type WalletTemplateScenarioBytecode, Input, assertSuccess, decodeAuthenticationInstructions, AuthenticationInstructionPush } from '@bitauth/libauth';
44
import { EncodedFunctionArgument } from '../Argument.js';
55
import { zip } from '../utils.js';
66
import SignatureTemplate from '../SignatureTemplate.js';
@@ -112,3 +112,15 @@ interface LibauthTemplateTokenDetails {
112112
export const lockingBytecodeIsSetToSlot = (lockingBytecode?: WalletTemplateScenarioBytecode | ['slot']): boolean => {
113113
return Array.isArray(lockingBytecode) && lockingBytecode.length === 1 && lockingBytecode[0] === 'slot';
114114
};
115+
116+
export const getSignatureAndPubkeyFromP2PKHInput = (
117+
libauthInput: Input,
118+
): { signature: Uint8Array; publicKey: Uint8Array } => {
119+
const inputData = (assertSuccess(
120+
decodeAuthenticationInstructions(libauthInput.unlockingBytecode))
121+
) as AuthenticationInstructionPush[];
122+
const signature = inputData[0].data;
123+
const publicKey = inputData[1].data;
124+
125+
return { signature, publicKey };
126+
};

packages/cashscript/src/utils.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -373,15 +373,3 @@ export const isFungibleTokenUtxo = (utxo: Utxo): boolean => (
373373
export const isNonTokenUtxo = (utxo: Utxo): boolean => utxo.token === undefined;
374374

375375
export const delay = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));
376-
377-
export const getSignatureAndPubkeyFromP2PKHInput = (
378-
libauthInput: Input,
379-
): { signature: Uint8Array; publicKey: Uint8Array } => {
380-
const inputData = (assertSuccess(
381-
decodeAuthenticationInstructions(libauthInput.unlockingBytecode)) as AuthenticationInstructions
382-
) as AuthenticationInstructionPush[];
383-
const signature = inputData[0].data;
384-
const publicKey = inputData[1].data;
385-
386-
return { signature, publicKey };
387-
};

packages/cashscript/test/debugging-old-artifacts.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('Debugging tests - old artifacts', () => {
3535
.addInput(contractUtxo, contractTestLogs.unlock.spend(alicePub, new SignatureTemplate(alicePriv)))
3636
.addOutput({ to: contractTestLogs.address, amount: 10000n });
3737

38-
console.warn(transaction.bitauthUri());
38+
console.warn(transaction.getBitauthUri());
3939

4040
expect(() => transaction.debug()).not.toThrow();
4141
});
@@ -50,7 +50,7 @@ describe('Debugging tests - old artifacts', () => {
5050
.addInput(contractUtxo, contractTestLogs.unlock.spend(alicePub, new SignatureTemplate(bobPriv)))
5151
.addOutput({ to: contractTestLogs.address, amount: 10000n });
5252

53-
console.warn(transaction.bitauthUri());
53+
console.warn(transaction.getBitauthUri());
5454

5555
expect(() => transaction.debug()).toThrow();
5656
});

packages/cashscript/test/e2e/MultiContract.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('Multi Contract', () => {
8787
.addInput(bobAddressUtxos[0], bobSignatureTemplate.unlockP2PKH())
8888
.addOutput({ to, amount });
8989

90-
console.log(transaction.bitauthUri());
90+
console.log(transaction.getBitauthUri());
9191

9292
const txPromise = transaction.send();
9393

@@ -173,7 +173,7 @@ describe('Multi Contract', () => {
173173
.addInput(bobAddressUtxos[0], bobSignatureTemplate.unlockP2PKH())
174174
.addOutput({ to, amount });
175175

176-
console.log(transaction.bitauthUri());
176+
console.log(transaction.getBitauthUri());
177177

178178
const txPromise = transaction.send();
179179

packages/cashscript/test/libauth-template/LibauthTemplate.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe('Libauth Template generation tests (single-contract)', () => {
55
it(`should generate a valid libauth template for ${fixture.name}`, () => {
66
const generatedTemplate = fixture.transaction.getLibauthTemplate();
77
// console.warn(JSON.stringify(generatedTemplate, null, 2));
8-
// console.warn(fixture.transaction.bitauthUri());
8+
// console.warn(fixture.transaction.getBitauthUri());
99
expect(generatedTemplate).toEqual(fixture.template);
1010
});
1111
});

packages/cashscript/test/libauth-template/LibauthTemplateMultiContract.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('Libauth Template generation tests (multi-contract)', () => {
66
const builder = await fixture.transaction;
77
const generatedTemplate = builder.getLibauthTemplate();
88
// console.warn(JSON.stringify(generatedTemplate, null, 2));
9-
// console.warn(builder.bitauthUri());
9+
// console.warn(builder.getBitauthUri());
1010
expect(generatedTemplate).toEqual(fixture.template);
1111
});
1212
});

packages/cashscript/test/multi-contract-debugging.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('Multi-Contract-Debugging tests', () => {
143143
.addInput(bobAddressUtxos[0], bobSignatureTemplate.unlockP2PKH())
144144
.addOutput({ to, amount });
145145

146-
console.warn(transaction.bitauthUri());
146+
console.warn(transaction.getBitauthUri());
147147

148148
await expect(transaction).toFailRequireWith('P2PKH.cash:4 Require statement failed at input 0 in contract P2PKH.cash at line 4.');
149149
});
@@ -169,7 +169,7 @@ describe('Multi-Contract-Debugging tests', () => {
169169
.addInput(bobAddressUtxos[0], bobSignatureTemplate.unlockP2PKH())
170170
.addOutput({ to, amount });
171171

172-
console.warn(transaction.bitauthUri());
172+
console.warn(transaction.getBitauthUri());
173173

174174
await expect(transaction).toFailRequireWith('BigInt.cash:4 Require statement failed at input 1 in contract BigInt.cash at line 4.');
175175
});
@@ -197,7 +197,7 @@ describe('Multi-Contract-Debugging tests', () => {
197197
.addInput(bobAddressUtxos[0], bobSignatureTemplate.unlockP2PKH())
198198
.addOutput({ to, amount });
199199

200-
console.warn(transaction.bitauthUri());
200+
console.warn(transaction.getBitauthUri());
201201

202202
await expect(transaction).toFailRequireWith('P2PKH.cash:5 Require statement failed at input 0 in contract P2PKH.cash at line 5');
203203
});
@@ -225,7 +225,7 @@ describe('Multi-Contract-Debugging tests', () => {
225225
.addInput(bobAddressUtxos[0], bobSignatureTemplate.unlockP2PKH())
226226
.addOutput({ to, amount });
227227

228-
console.warn(transaction.bitauthUri());
228+
console.warn(transaction.getBitauthUri());
229229

230230
await expect(transaction).toFailRequireWith('BigInt.cash');
231231
});

website/docs/guides/debugging.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ To help with debugging you can add `console.log` statements to your CashScript c
4242

4343
Whenever a transaction fails, there will be a link in the console to open your smart contract transaction in the BitAuth IDE. This will allow you to inspect the transaction in detail, and see exactly why the transaction failed. In the BitAuth IDE you will see the raw BCH Script mapping to each line in your CashScript contract. Find the failing line and investigate the failing OpCode. You can break up the failing line, one opcode at a time, to see how the stack evolves and ends with your `require` failure.
4444

45-
It's also possible to export the transaction for step-by-step debugging in the BitAuth IDE without failure. To do so, you can call the `bitauthUri()` function on the transaction. This will return a URI that can be opened in the BitAuth IDE.
45+
It's also possible to export the transaction for step-by-step debugging in the BitAuth IDE without failure. To do so, you can call the `getBitauthUri()` function on the transaction. This will return a URI that can be opened in the BitAuth IDE.
4646

4747
```ts
48-
const uri = await transactionBuilder.bitauthUri();
48+
const uri = await transactionBuilder.getBitauthUri();
4949
```
5050

5151
:::caution
@@ -75,7 +75,7 @@ OP_3 OP_ROLL OP_SWAP OP_CHECKSIGVERIFY /* require(checkSig(senderSig, se
7575
OP_SWAP OP_CHECKLOCKTIMEVERIFY /* require(tx.time >= timeout); */
7676
OP_2DROP OP_1 /* } */
7777
OP_ENDIF /* } */
78-
78+
7979
```
8080

8181
[BitauthIDE]: https://ide.bitauth.com/import-template/eJzFWAtv2zYQ_isCN2BJ4drUW8raAK3jNkbSJEvcFUMdGBR1stXakidRWYIg--07SrIk23LgDhlGBKEiHu-7x3fUMY_k55TPYMHIEZkJsUyPer3Qh64XCpaJWZfHi558gEiEnIkwjl4LWCznTMDrO9ot9na_pXFEOsSHlCfhUkqhuuFiGScCfCVI4oXCWTorVlEwYgtAiT6-u8nfKR8hgoRJ6RPwsuk0jKbKqATCDWm2LJSRo6_kff90olHNnFCT3HbIHSRpjkg7RJopQkjJ0SMZJSxKA0i-hGI2ChcQZ2ISRstM0MmSJWiBwI1ScN3sfhyJhHGh8ARyhxUWoQ9ZxPM_GlsrP1qQlIMcSvmJHkrzc_2pNL7NqnnMv6NU25JYNzyLclnpNUtC5s0LV1OIfEhuwum2O-N6cUxq65U4qH0akxJmTGqnap0dIh6W8tUZPJCnTrmyG2oTR8zCVOFlWDcBau1f2HwO4oQJJkES4OEyxHy24VSLe0LVynaglf63YVWh2QtppWgHzirkmE8f7rfhymqoMpOLKSJW4B54lpdCCbShqRUPR4N77RXRTjAUXrI0hZ2U3dgGd2yeyVK93YxEWyHgaq_XZF1beY2jNxUF5TkTxUkyScNpxESWQBfdnOBeVJ1O5HMm7uP0WEG9KDOOxhE-bYQxjKqEofL1AOY7w0gob5U36vFYnmZFKNL2-i5q9qm9aFchlDMeZKMiM0stnenas6fGVoRaZDBavDqi4igVScZFnKxHroxs0yt671KfUh2de1PVQy6wzLzv8FDIUN0JTNM0HN8OdF91dA6e5wDYNtWtAMAzqBMYzKQ6DTzDsWzVtkzX81zDCMDEZX5cJW5buaY6vqFalmq5mouPGlcD29JBM3QwPNPjuh84oOIyZcw1dU-1mQVUc6lmaWbg0uMys96DAB77MI6U_UbvlbJM2HTBGh8i5W_aVdUu_XVPHc3xqvcj0C86fgy64koLlQ7K5BTp6qxyVbGjk3On5NKh8vgvvMZcXcOfWZhArfaXV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