@neuraiproject/neurai-assets 1.8.1 → 1.8.2

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/README.md CHANGED
@@ -37,6 +37,18 @@ Complete asset management library for Neurai blockchain. Supports creation, reis
37
37
  > (full name, owner `!` included: 31 mainnet / 121 testnet-regtest, validated
38
38
  > against a regtest node); peer `neurai-rpc ^0.6.0`.
39
39
 
40
+ ## 1.8.2: Transfer amounts given as decimal strings
41
+
42
+ `transferAsset` failed with `Invalid parameter, missing or invalid quantity`
43
+ on nodes before Neurai-DePIN `9834b03` (mainnet and testnet at the time of
44
+ writing) when a recipient `amount` was a decimal string such as `"5"`, or when
45
+ the asset change back to the sender was one that no JavaScript number carries
46
+ exactly (the builder writes those as text). Those nodes read the amounts of
47
+ `transfer` and `transferwithmessage` only from JSON numbers, like
48
+ `asset_quantity`. They are now converted the same way as in 1.8.1, on the copy
49
+ sent to the node; `message` and `expire_time` are left untouched. Numeric
50
+ amounts are unchanged.
51
+
40
52
  ## 1.8.1: Issue quantities given as decimal strings
41
53
 
42
54
  `createRootAsset`, `createSubAsset`, `createDepinAsset` and
@@ -98,12 +110,13 @@ via `CheckAmountWithUnits`. Because the chain already does the ×10⁸ scaling
98
110
  itself, **the library must NOT pre-multiply** the value. Sending the raw
99
111
  display number is the only correct behavior; any extra factor on the wire
100
112
  either silently inflates the minted supply (`× 10⁸ → 100,000,000` tokens
101
- where the user asked for 1) or trips the daemon's
102
- `ParseFixedPoint` cap with `Invalid amount (3): …`.
113
+ where the user asked for 1) or falls outside the range the daemon's amount
114
+ parser accepts, with `Invalid amount (3): …`.
103
115
 
104
- A quantity can be a number or a plain decimal string (`"1000.25"`). A string
105
- keeps every digit; it is sent to the node as a JSON number, which is the only
106
- form `createrawtransaction` accepts for `asset_quantity`. A decimal that no
116
+ A quantity or transfer amount can be a number or a plain decimal string
117
+ (`"1000.25"`). A string keeps every digit; it is sent to the node as a JSON
118
+ number, the only form nodes before Neurai-DePIN `9834b03` accept for asset
119
+ amounts in `createrawtransaction` (newer nodes accept both). A decimal that no
107
120
  JavaScript number carries exactly is sent as an exact token, which requires
108
121
  the RPC function to serialize with `@neuraiproject/neurai-rpc` (its
109
122
  `getRPC()` does); any other serializer makes the node reject the call instead
@@ -8302,13 +8302,17 @@ var NeuraiAssetsBundle = (function (exports) {
8302
8302
  /**
8303
8303
  * Asset amounts as `createrawtransaction` must receive them.
8304
8304
  *
8305
- * The node reads `asset_quantity` (issue, issue_restricted, issue_qualifier,
8306
- * reissue, reissue_restricted) and `change_quantity` (qualifier and tag
8307
- * operations) only from JSON numbers: a quoted value fails `isNum()` and the
8308
- * call is rejected with "missing asset data for key: asset_quantity". The
8309
- * builders accept these amounts as decimal strings, which keep every digit the
8310
- * caller wrote, so they are turned into JSON numbers here, on the copy of the
8311
- * outputs sent to the node. The outputs returned to the caller keep the value
8305
+ * Nodes before Neurai-DePIN 9834b03 read every asset amount of
8306
+ * `createrawtransaction` only from JSON numbers: `asset_quantity` (issue,
8307
+ * issue_restricted, issue_qualifier, reissue, reissue_restricted),
8308
+ * `change_quantity` (qualifier and tag operations) and the amounts of
8309
+ * `transfer` and `transferwithmessage`. A quoted value fails `isNum()` and the
8310
+ * call is rejected ("missing asset data for key: asset_quantity", "missing or
8311
+ * invalid quantity"). The builders accept these amounts as decimal strings,
8312
+ * which keep every digit the caller wrote, and produce some themselves (an
8313
+ * asset change that no JavaScript number carries exactly), so they are turned
8314
+ * into JSON numbers here, on the copy of the outputs sent to the node. Newer
8315
+ * nodes accept both forms. The outputs returned to the caller keep the value
8312
8316
  * as it was given.
8313
8317
  */
8314
8318
 
@@ -8328,6 +8332,14 @@ var NeuraiAssetsBundle = (function (exports) {
8328
8332
  /** Fields the node parses with `isNum()` inside an asset operation object. */
8329
8333
  const NUMERIC_OPERATION_FIELDS = ['asset_quantity', 'change_quantity'];
8330
8334
 
8335
+ /**
8336
+ * Operations whose keys are asset names mapped to amounts. `transferwithmessage`
8337
+ * also carries `message` (a string) and `expire_time` (an integer), which are
8338
+ * not amounts and are left alone.
8339
+ */
8340
+ const TRANSFER_OPERATIONS = ['transfer', 'transferwithmessage'];
8341
+ const TRANSFER_NON_AMOUNT_KEYS = ['message', 'expire_time'];
8342
+
8331
8343
  /** The largest magnitude whose 8-decimal values a double still names exactly. */
8332
8344
  const MAX_EXACT_FRACTIONAL = Number.MAX_SAFE_INTEGER / 1e8;
8333
8345
 
@@ -8384,10 +8396,11 @@ var NeuraiAssetsBundle = (function (exports) {
8384
8396
  }
8385
8397
 
8386
8398
  /**
8387
- * Copy of `createrawtransaction` outputs with the numeric asset fields
8388
- * converted by {@link toRpcAmount}. XNA amounts and every other field are left
8389
- * as they are: the node reads those with `AmountFromValue`, which also accepts
8390
- * strings.
8399
+ * Copy of `createrawtransaction` outputs with the asset amounts converted by
8400
+ * {@link toRpcAmount}: `asset_quantity` and `change_quantity`, and the amounts
8401
+ * of `transfer` / `transferwithmessage`. XNA amounts and every other field are
8402
+ * left as they are: the node reads XNA amounts with `AmountFromValue`, which
8403
+ * also accepts strings.
8391
8404
  *
8392
8405
  * @param {Array<object>|object} outputs - Outputs as built (array of single-key objects, or one object)
8393
8406
  * @returns {Array<object>|object} Outputs to send, same shape
@@ -8404,9 +8417,17 @@ var NeuraiAssetsBundle = (function (exports) {
8404
8417
  continue;
8405
8418
  }
8406
8419
  const copy = { ...params };
8407
- for (const field of NUMERIC_OPERATION_FIELDS) {
8408
- if (copy[field] !== undefined && copy[field] !== null) {
8409
- copy[field] = toRpcAmount(copy[field], field);
8420
+ if (TRANSFER_OPERATIONS.includes(operation)) {
8421
+ for (const [key, value] of Object.entries(copy)) {
8422
+ if (!TRANSFER_NON_AMOUNT_KEYS.includes(key) && value !== undefined && value !== null) {
8423
+ copy[key] = toRpcAmount(value, `${operation} amount of ${key}`);
8424
+ }
8425
+ }
8426
+ } else {
8427
+ for (const field of NUMERIC_OPERATION_FIELDS) {
8428
+ if (copy[field] !== undefined && copy[field] !== null) {
8429
+ copy[field] = toRpcAmount(copy[field], field);
8430
+ }
8410
8431
  }
8411
8432
  }
8412
8433
  converted[operation] = copy;
@@ -8790,8 +8811,9 @@ var NeuraiAssetsBundle = (function (exports) {
8790
8811
  vout: input.vout !== undefined ? input.vout : input.outputIndex
8791
8812
  }));
8792
8813
 
8793
- // Call createrawtransaction. The node only accepts the asset quantities
8794
- // as JSON numbers; the caller's outputs keep the values as given.
8814
+ // Call createrawtransaction. Nodes before Neurai-DePIN 9834b03 only
8815
+ // accept asset amounts as JSON numbers; the caller's outputs keep the
8816
+ // values as given.
8795
8817
  const rawTx = await this.rpc('createrawtransaction', [
8796
8818
  formattedInputs,
8797
8819
  prepareOutputsForRpc(outputs)
@@ -8926,8 +8948,8 @@ var NeuraiAssetsBundle = (function (exports) {
8926
8948
  * (e.g. "1" for one token, "1.5" for one and a half tokens).
8927
8949
  * - The lib must NOT pre-multiply by 10^8 or 10^units; the daemon
8928
8950
  * does the 10^8 scaling itself, and any extra factor here lands
8929
- * duplicated and inflates the minted supply (or trips the
8930
- * ParseFixedPoint `exponent >= 18` cap → "Invalid amount (3)").
8951
+ * duplicated and inflates the minted supply (or falls outside the
8952
+ * range the node's amount parser accepts → "Invalid amount (3)").
8931
8953
  *
8932
8954
  * History: pre-1.2.2 multiplied by 10^units (correct only for units=0
8933
8955
  * assets, inflated everything else by 10^units). v1.2.2 changed to