@fuel-ts/account 0.0.0-pr-2364-20240523174104 → 0.0.0-pr-2364-20240524224403

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.

Potentially problematic release.


This version of @fuel-ts/account might be problematic. Click here for more details.

@@ -1765,6 +1765,8 @@ var import_transactions6 = require("@fuel-ts/transactions");
1765
1765
  var isRequestInputCoin = (input) => input.type === import_transactions6.InputType.Coin;
1766
1766
  var isRequestInputMessage = (input) => input.type === import_transactions6.InputType.Message;
1767
1767
  var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
1768
+ var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
1769
+ var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
1768
1770
  var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
1769
1771
  if (isRequestInputCoin(input) && input.assetId === assetId) {
1770
1772
  return acc.add(input.amount);
@@ -2027,7 +2029,7 @@ var BaseTransactionRequest = class {
2027
2029
  * @param coin - Coin resource.
2028
2030
  */
2029
2031
  addCoinInput(coin) {
2030
- const { assetId, owner, amount, id, predicate } = coin;
2032
+ const { assetId, owner, amount, id, predicate, predicateData } = coin;
2031
2033
  let witnessIndex;
2032
2034
  if (coin.predicate) {
2033
2035
  witnessIndex = 0;
@@ -2045,7 +2047,8 @@ var BaseTransactionRequest = class {
2045
2047
  assetId,
2046
2048
  txPointer: "0x00000000000000000000000000000000",
2047
2049
  witnessIndex,
2048
- predicate
2050
+ predicate,
2051
+ predicateData
2049
2052
  };
2050
2053
  this.pushInput(input);
2051
2054
  this.addChangeOutput(owner, assetId);
@@ -2057,7 +2060,7 @@ var BaseTransactionRequest = class {
2057
2060
  * @param message - Message resource.
2058
2061
  */
2059
2062
  addMessageInput(message) {
2060
- const { recipient, sender, amount, predicate, nonce, assetId } = message;
2063
+ const { recipient, sender, amount, predicate, nonce, assetId, predicateData } = message;
2061
2064
  let witnessIndex;
2062
2065
  if (message.predicate) {
2063
2066
  witnessIndex = 0;
@@ -2074,7 +2077,8 @@ var BaseTransactionRequest = class {
2074
2077
  recipient: recipient.toB256(),
2075
2078
  amount,
2076
2079
  witnessIndex,
2077
- predicate
2080
+ predicate,
2081
+ predicateData
2078
2082
  };
2079
2083
  this.pushInput(input);
2080
2084
  this.addChangeOutput(recipient, assetId);
@@ -2276,23 +2280,13 @@ var BaseTransactionRequest = class {
2276
2280
  });
2277
2281
  }
2278
2282
  updatePredicateGasUsed(inputs) {
2279
- this.inputs.forEach((i) => {
2280
- let correspondingInput;
2281
- switch (i.type) {
2282
- case import_transactions7.InputType.Coin:
2283
- correspondingInput = inputs.find((x) => x.type === import_transactions7.InputType.Coin && x.owner === i.owner);
2284
- break;
2285
- case import_transactions7.InputType.Message:
2286
- correspondingInput = inputs.find(
2287
- (x) => x.type === import_transactions7.InputType.Message && x.sender === i.sender
2288
- );
2289
- break;
2290
- default:
2291
- return;
2292
- }
2283
+ const inputsToExtractGasUsed = inputs.filter(isRequestInputResource);
2284
+ this.inputs.filter(isRequestInputResource).forEach((i) => {
2285
+ const owner = getRequestInputResourceOwner(i);
2286
+ const correspondingInput = inputsToExtractGasUsed.find(
2287
+ (x) => isRequestInputResourceFromOwner(x, import_address.Address.fromString(String(owner)))
2288
+ );
2293
2289
  if (correspondingInput && "predicateGasUsed" in correspondingInput && (0, import_math8.bn)(correspondingInput.predicateGasUsed).gt(0)) {
2294
- i.predicate = correspondingInput.predicate;
2295
- i.predicateData = correspondingInput.predicateData;
2296
2290
  i.predicateGasUsed = correspondingInput.predicateGasUsed;
2297
2291
  }
2298
2292
  });