@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.

@@ -1751,6 +1751,8 @@ import { InputType as InputType2 } from "@fuel-ts/transactions";
1751
1751
  var isRequestInputCoin = (input) => input.type === InputType2.Coin;
1752
1752
  var isRequestInputMessage = (input) => input.type === InputType2.Message;
1753
1753
  var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
1754
+ var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
1755
+ var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
1754
1756
  var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
1755
1757
  if (isRequestInputCoin(input) && input.assetId === assetId) {
1756
1758
  return acc.add(input.amount);
@@ -2013,7 +2015,7 @@ var BaseTransactionRequest = class {
2013
2015
  * @param coin - Coin resource.
2014
2016
  */
2015
2017
  addCoinInput(coin) {
2016
- const { assetId, owner, amount, id, predicate } = coin;
2018
+ const { assetId, owner, amount, id, predicate, predicateData } = coin;
2017
2019
  let witnessIndex;
2018
2020
  if (coin.predicate) {
2019
2021
  witnessIndex = 0;
@@ -2031,7 +2033,8 @@ var BaseTransactionRequest = class {
2031
2033
  assetId,
2032
2034
  txPointer: "0x00000000000000000000000000000000",
2033
2035
  witnessIndex,
2034
- predicate
2036
+ predicate,
2037
+ predicateData
2035
2038
  };
2036
2039
  this.pushInput(input);
2037
2040
  this.addChangeOutput(owner, assetId);
@@ -2043,7 +2046,7 @@ var BaseTransactionRequest = class {
2043
2046
  * @param message - Message resource.
2044
2047
  */
2045
2048
  addMessageInput(message) {
2046
- const { recipient, sender, amount, predicate, nonce, assetId } = message;
2049
+ const { recipient, sender, amount, predicate, nonce, assetId, predicateData } = message;
2047
2050
  let witnessIndex;
2048
2051
  if (message.predicate) {
2049
2052
  witnessIndex = 0;
@@ -2060,7 +2063,8 @@ var BaseTransactionRequest = class {
2060
2063
  recipient: recipient.toB256(),
2061
2064
  amount,
2062
2065
  witnessIndex,
2063
- predicate
2066
+ predicate,
2067
+ predicateData
2064
2068
  };
2065
2069
  this.pushInput(input);
2066
2070
  this.addChangeOutput(recipient, assetId);
@@ -2262,23 +2266,13 @@ var BaseTransactionRequest = class {
2262
2266
  });
2263
2267
  }
2264
2268
  updatePredicateGasUsed(inputs) {
2265
- this.inputs.forEach((i) => {
2266
- let correspondingInput;
2267
- switch (i.type) {
2268
- case InputType3.Coin:
2269
- correspondingInput = inputs.find((x) => x.type === InputType3.Coin && x.owner === i.owner);
2270
- break;
2271
- case InputType3.Message:
2272
- correspondingInput = inputs.find(
2273
- (x) => x.type === InputType3.Message && x.sender === i.sender
2274
- );
2275
- break;
2276
- default:
2277
- return;
2278
- }
2269
+ const inputsToExtractGasUsed = inputs.filter(isRequestInputResource);
2270
+ this.inputs.filter(isRequestInputResource).forEach((i) => {
2271
+ const owner = getRequestInputResourceOwner(i);
2272
+ const correspondingInput = inputsToExtractGasUsed.find(
2273
+ (x) => isRequestInputResourceFromOwner(x, Address.fromString(String(owner)))
2274
+ );
2279
2275
  if (correspondingInput && "predicateGasUsed" in correspondingInput && bn8(correspondingInput.predicateGasUsed).gt(0)) {
2280
- i.predicate = correspondingInput.predicate;
2281
- i.predicateData = correspondingInput.predicateData;
2282
2276
  i.predicateGasUsed = correspondingInput.predicateGasUsed;
2283
2277
  }
2284
2278
  });