cashscript 0.8.0-next.4 → 0.8.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.
@@ -1,6 +1,7 @@
1
1
  import { hexToBin, binToHex, encodeTransaction, decodeTransaction, } from '@bitauth/libauth';
2
2
  import delay from 'delay';
3
3
  import { hash256, placeholder, scriptToBytecode, } from '@cashscript/utils';
4
+ import deepEqual from 'fast-deep-equal';
4
5
  import { isSignableUtxo, } from './interfaces.js';
5
6
  import { meep, createInputScript, getInputSize, createOpReturnOutput, getTxSizeWithoutInputs, getPreimageSize, buildError, createSighashPreimage, validateRecipient, utxoComparator, cashScriptOutputToLibauthOutput, calculateDust, getOutputSize, addressToLockScript, publicKeyToP2PKHLockingBytecode, utxoTokenComparator, } from './utils.js';
6
7
  import SignatureTemplate from './SignatureTemplate.js';
@@ -179,13 +180,13 @@ export class Transaction {
179
180
  throw Error('Attempted to build a transaction without outputs');
180
181
  }
181
182
  const allUtxos = await this.provider.getUtxos(this.address);
182
- const manualTokenInputs = this.inputs.filter((input) => input.token);
183
- // This will throw if the amount is not enough
184
- if (manualTokenInputs.length > 0) {
185
- selectAllTokenUtxos(manualTokenInputs, this.outputs);
183
+ const tokenInputs = this.inputs.length > 0
184
+ ? this.inputs.filter((input) => input.token)
185
+ : selectAllTokenUtxos(allUtxos, this.outputs);
186
+ // This throws if the manually selected inputs are not enough to cover the outputs
187
+ if (this.inputs.length > 0) {
188
+ selectAllTokenUtxos(this.inputs, this.outputs);
186
189
  }
187
- const automaticTokenInputs = selectAllTokenUtxos(allUtxos, this.outputs);
188
- const tokenInputs = manualTokenInputs.length > 0 ? manualTokenInputs : automaticTokenInputs;
189
190
  if (this.tokenChange) {
190
191
  const tokenChangeOutputs = createFungibleTokenChangeOutputs(tokenInputs, this.outputs, this.address);
191
192
  this.outputs.push(...tokenChangeOutputs);
@@ -221,9 +222,9 @@ export class Transaction {
221
222
  if (nftInput.capability === 'none') {
222
223
  for (let i = 0; i < listNftsOutputs.length; i += 1) {
223
224
  // Deep equality check token objects
224
- if (JSON.stringify(listNftsOutputs[i]) === JSON.stringify(nftInput)) {
225
+ if (deepEqual(listNftsOutputs[i], nftInput)) {
225
226
  listNftsOutputs.splice(i, 1);
226
- unusedNfts = unusedNfts.filter((nft) => nft !== nftInput);
227
+ unusedNfts = unusedNfts.filter((nft) => !deepEqual(nft, nftInput));
227
228
  break;
228
229
  }
229
230
  }
@@ -234,7 +235,7 @@ export class Transaction {
234
235
  // eslint-disable-next-line max-len
235
236
  const newListNftsOutputs = listNftsOutputs.filter((nftOutput) => nftOutput.category !== nftInput.category);
236
237
  if (newListNftsOutputs !== listNftsOutputs) {
237
- unusedNfts = unusedNfts.filter((nft) => nft !== nftInput);
238
+ unusedNfts = unusedNfts.filter((nft) => !deepEqual(nft, nftInput));
238
239
  listNftsOutputs = newListNftsOutputs;
239
240
  }
240
241
  }
@@ -242,7 +243,7 @@ export class Transaction {
242
243
  for (let i = 0; i < listNftsOutputs.length; i += 1) {
243
244
  if (listNftsOutputs[i].category === nftInput.category) {
244
245
  listNftsOutputs.splice(i, 1);
245
- unusedNfts = unusedNfts.filter((nft) => nft !== nftInput);
246
+ unusedNfts = unusedNfts.filter((nft) => !deepEqual(nft, nftInput));
246
247
  break;
247
248
  }
248
249
  }
@@ -251,7 +252,7 @@ export class Transaction {
251
252
  for (const nftOutput of listNftsOutputs) {
252
253
  const genesisUtxo = getTokenGenesisUtxo(this.inputs, nftOutput.category);
253
254
  if (genesisUtxo) {
254
- listNftsOutputs = listNftsOutputs.filter((nft) => nft !== nftOutput);
255
+ listNftsOutputs = listNftsOutputs.filter((nft) => !deepEqual(nft, nftOutput));
255
256
  }
256
257
  }
257
258
  if (listNftsOutputs.length !== 0) {
@@ -304,7 +305,7 @@ export class Transaction {
304
305
  // even if they report UTXOs in a different order
305
306
  bchUtxos.sort(utxoComparator).reverse();
306
307
  // Add all automatically added token inputs to the transaction
307
- for (const utxo of automaticTokenInputs) {
308
+ for (const utxo of tokenInputs) {
308
309
  this.inputs.push(utxo);
309
310
  satsAvailable += addPrecision(utxo.satoshis);
310
311
  if (!this.hardcodedFee)
package/dist/index.d.ts CHANGED
@@ -2,9 +2,9 @@ import SignatureTemplate from './SignatureTemplate.js';
2
2
  export { SignatureTemplate };
3
3
  export { Contract, ContractFunction } from './Contract.js';
4
4
  export { Transaction } from './Transaction.js';
5
- export { Argument } from './Argument.js';
5
+ export { Argument, encodeArgument } from './Argument.js';
6
6
  export { Artifact, AbiFunction, AbiInput } from '@cashscript/utils';
7
7
  export * as utils from '@cashscript/utils';
8
- export { Utxo, Recipient, SignatureAlgorithm, HashType, Network, } from './interfaces.js';
8
+ export { Utxo, Recipient, SignatureAlgorithm, HashType, Network, isSignableUtxo, } from './interfaces.js';
9
9
  export * from './Errors.js';
10
10
  export { NetworkProvider, BitcoinRpcNetworkProvider, ElectrumNetworkProvider, FullStackNetworkProvider, } from './network/index.js';
package/dist/index.js CHANGED
@@ -2,8 +2,9 @@ import SignatureTemplate from './SignatureTemplate.js';
2
2
  export { SignatureTemplate };
3
3
  export { Contract } from './Contract.js';
4
4
  export { Transaction } from './Transaction.js';
5
+ export { encodeArgument } from './Argument.js';
5
6
  export * as utils from '@cashscript/utils';
6
- export { SignatureAlgorithm, HashType, Network, } from './interfaces.js';
7
+ export { SignatureAlgorithm, HashType, Network, isSignableUtxo, } from './interfaces.js';
7
8
  export * from './Errors.js';
8
9
  export { BitcoinRpcNetworkProvider, ElectrumNetworkProvider, FullStackNetworkProvider, } from './network/index.js';
9
10
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cashscript",
3
- "version": "0.8.0-next.4",
3
+ "version": "0.8.1",
4
4
  "description": "Easily write and interact with Bitcoin Cash contracts",
5
5
  "keywords": [
6
6
  "bitcoin cash",
@@ -44,11 +44,12 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@bitauth/libauth": "^2.0.0-alpha.8",
47
- "@cashscript/utils": "^0.8.0-next.4",
47
+ "@cashscript/utils": "^0.8.1",
48
48
  "bip68": "^1.0.4",
49
49
  "bitcoin-rpc-promise-retry": "^1.3.0",
50
50
  "delay": "^5.0.0",
51
- "electrum-cash": "^2.0.10"
51
+ "electrum-cash": "^2.0.10",
52
+ "fast-deep-equal": "^3.1.3"
52
53
  },
53
54
  "devDependencies": {
54
55
  "@jest/globals": "^29.4.1",
@@ -58,5 +59,5 @@
58
59
  "jest": "^29.4.1",
59
60
  "typescript": "^4.1.5"
60
61
  },
61
- "gitHead": "f4c3f9c21cca98465e5cad919e64b4c6292e9a1f"
62
+ "gitHead": "a70a5a57a938bc81fdf4180b1451cfcc0ff0214b"
62
63
  }