Page MenuHomePhabricator

[Cashtab] [Chronik] [Tx Gen] generateTokenTxOutput - part 1 token genesis tx
ClosedPublic

Authored by emack on Oct 1 2022, 03:54.

Details

Summary

See T2503 for the pseudocode behind the generateTokenTxOutput function and how it'll be used by overarching token functions.

Part 1 caters for the genesis token tx where the relevant OP_RETURN script and token/xec outputs are added to the transaction builder.

Subsequent diff in this stack will cover the SEND/BURN OP_RETURN scripts and the additional outputs for token send/burn and token change.

Test Plan

npm test and ensure the genesis unit test passes

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

emack requested review of this revision.Oct 1 2022, 03:54
bytesofman requested changes to this revision.Oct 7 2022, 17:49
bytesofman added inline comments.
web/cashtab/src/utils/cashMethods.js
47 ↗(On Diff #35334)

optional values should be given default values so the function knows if they were not included. Also, the non-optional txBuilder object should not be the last parameter.

79 ↗(On Diff #35334)

we use currency.dustSats for this comparison in other functions.

currency.etokenSats, at 546, is technically the correct minimum. But cashtab uses 550 sats for consistency and also as a bonus way to distinguish between cashtab token and cashtab xec txs.

Follow the current cashtab convention. If we decide to change it later, we'll change it everywhere.

This revision now requires changes to proceed.Oct 7 2022, 17:49
emack marked 2 inline comments as done.
  • added default values to optional params in generateTokenTxOutput()
  • moved up txBuilder param in arg order
  • changed remainder minimum to reference currency.dustSats

Tail of the build log:

npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'postcss-place@7.0.5',
npm WARN EBADENGINE   required: { node: '^12 || ^14 || >=16' },
npm WARN EBADENGINE   current: { node: 'v15.14.0', npm: '7.7.6' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'postcss-preset-env@7.8.2',
npm WARN EBADENGINE   required: { node: '^12 || ^14 || >=16' },
npm WARN EBADENGINE   current: { node: 'v15.14.0', npm: '7.7.6' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'postcss-pseudo-class-any-link@7.1.6',
npm WARN EBADENGINE   required: { node: '^12 || ^14 || >=16' },
npm WARN EBADENGINE   current: { node: 'v15.14.0', npm: '7.7.6' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'postcss-selector-not@6.0.1',
npm WARN EBADENGINE   required: { node: '^12 || ^14 || >=16' },
npm WARN EBADENGINE   current: { node: 'v15.14.0', npm: '7.7.6' }
npm WARN EBADENGINE }
npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
npm WARN deprecated text-encoding@0.6.4: no longer maintained
npm WARN deprecated ts-custom-error@2.2.2: npm package tarball contains useless codeclimate-reporter binary, please update to version 3.1.1. See https://github.com/adriengibrat/ts-custom-error/issues/32

> cashtab@1.0.0 prepare
> cd ../.. && husky install web/cashtab/.husky

husky - Git hooks installed

added 1807 packages, and audited 1808 packages in 27s

232 packages are looking for funding
  run `npm fund` for details

5 moderate severity vulnerabilities

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.
npm notice 
npm notice New major version of npm available! 7.7.6 -> 8.19.2
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.19.2>
npm notice Run `npm install -g npm@8.19.2` to update!
npm notice 

> cashtab@1.0.0 build
> node scripts/build.js

Creating an optimized production build...
Failed to compile.

[eslint] 
src/utils/cashMethods.js
  Line 48:5:  'totalTokenInputUtxoValue' is assigned a value but never used  no-unused-vars

Search for the keywords to learn more about each error.


Build cashtab-tests failed with exit code 1

Default value for the totalTokenInputUtxoValue will be added in the next diff to avoid the '... varaible is defined but not used' build errors.

Default value for the totalTokenInputUtxoValue will be added in the next diff to avoid the '... varaible is defined but not used' build errors.

Provide it with some kind of placeholder value here, e.g. true or false and then console.log it to remove this build error.

I'm not sure if we can have a stacked diff land if one part isn't building.

This revision now requires changes to proceed.Oct 11 2022, 16:17

added default param value for totalTokenInputUtxoValue

bytesofman added inline comments.
web/cashtab/src/utils/cashMethods.js
61 ↗(On Diff #35594)

This cascading if...else based on a limited quantity of specific inputs should instead be a switch statement

https://www.w3schools.com/js/js_switch.asp

This revision now requires changes to proceed.Oct 12 2022, 16:24
emack marked an inline comment as done.

Updated with switch statement

This revision is now accepted and ready to land.Oct 13 2022, 18:07
  • aligning to part 3's dynamic destinationAddress logic in tokenAction switch statements
  • renamed misleading var names