Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow arbitrary destination address for token creation #66

Merged
merged 6 commits into from
Sep 11, 2023

Conversation

stanleyjones
Copy link
Contributor

I was getting started on #63 and I needed to change this feature anyway. Closes #39.

BEFORE

Screenshot 2023-08-10 at 10 10 33 AM

NOW

Screenshot 2023-08-10 at 10 11 15 AM

WITH VALIDATION

Screenshot 2023-08-10 at 10 05 42 AM

@netlify
Copy link

netlify bot commented Aug 10, 2023

Deploy Preview for lifted-gwen ready!

Name Link
🔨 Latest commit ecf4ee5
🔍 Latest deploy log https://app.netlify.com/sites/lifted-gwen/deploys/64fa1842f79fe30008b95aee
😎 Deploy Preview https://deploy-preview-66--lifted-gwen.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@codecov
Copy link

codecov bot commented Aug 10, 2023

Codecov Report

Merging #66 (ecf4ee5) into main (e533831) will decrease coverage by 0.15%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main      #66      +/-   ##
==========================================
- Coverage   29.29%   29.15%   -0.15%     
==========================================
  Files          61       61              
  Lines        1007     1012       +5     
  Branches      206      208       +2     
==========================================
  Hits          295      295              
- Misses        709      714       +5     
  Partials        3        3              
Files Changed Coverage Δ
src/api/services/queries/ledger.ts 0.00% <0.00%> (ø)
src/pages/services/ledger/create-token-modal.tsx 0.00% <0.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

📢 Have feedback on the report? Share it here.

@fmorency
Copy link
Contributor

Creating a new token using the pre-populated "Destination Address" results in an error, even if the address is correctly formatted.

2023-08-11_11-13

Also, the request made to the backend is malformed, resulting in a 500: Internal Error. The issue resides in how the Timestamp is encoded in CBOR.

GOOD (many-rs):

18([
    h'a3012604581d0119f0ec2aca1eae0d7405d2bb69edb256be44c68378052193ddce93a4666b6579736574587181a7010202581d0119f0ec2aca1eae0d7405d2bb69edb256be44c68378052193ddce93a4032604810220012158206112eec037fb20b6c8e11a22ffa0b4842892d03986cbe29a45cb50cfda6da35622582082454c56fb76249416821e339dfcccda743a7f47a84027fc85e6c0087b8bbbd1',
    {},
    h'd92711a501d92710581d0119f0ec2aca1eae0d7405d2bb69edb256be44c68378052193ddce93a4036d746f6b656e732e637265617465045833a200a30064544553540163545354020901d92710581d0119f0ec2aca1eae0d7405d2bb69edb256be44c68378052193ddce93a405c11a64d65345075051ad338c07d4683eb1c56a794a26f9fb',
    h'cbe870676165a4e7e781c1d88f24e4f47e73901ad45236292e9b287f25db2cfee3cbc9068111169897dd17463c9f4ac9e3ffa89b97c7d33d2635387612a9a45c',
])

BAD (this PR):

18([
    h'a3012704581d01f2e272e51c5fd0b02abeeb8bbef05fee26e112eba264734919b867c9666b6579736574585081a6010102581d01f2e272e51c5fd0b02abeeb8bbef05fee26e112eba264734919b867c90327048102200621d8405820d1931c94ba5b226df8c5e2ebb71b0cdd6bd3f75d3bf7184a1c3fe31ed25a440a',
    {},
    h'd92711a600010178326d61687a6f6534786664727035626d626b78337679787078716c3778636e796973356f72676934326a64673467707369646a036d746f6b656e732e637265617465045874a300a30066466f6f6261720163464252020901d92710581d01f2e272e51c5fd0b02abeeb8bbef05fee26e112eba264734919b867c902a178326d61687a6f6534786664727035626d626b78337679787078716c3778636e796973356f72676934326a64673467707369646ac247038d7ea4c6800005c11a64d652550753d84050169ddceefe4b36aa00ec7435e4b41e4f',
    64(h'c0f9abfe60fde1aea676948f5707fae0e4e3b85f65d6b0210ad5fc3c98dd7f05390243a8eba92d50eb44b8adf3a16e9baf8542dc0e624dbbd9ca78e9f5430a05'),
])

Notice that the last field is tagged with a 64, which is wrong.

@stanleyjones
Copy link
Contributor Author

The 64 tag is for a Uint8Array and is probably because of the Buffer polyfill we were using. Now that we've rolled back to an earlier version I'm going to see if this works again.

@stanleyjones
Copy link
Contributor Author

The request is now accepted by the backend (no internal server error) but the tokens are still being assigned to the sender and not the address specified. Investigating.

@stanleyjones
Copy link
Contributor Author

Okay, I found and fixed a bug and the request seems to be correct now:

18([
     h'A3012704581D014A101D521D810211A0C6346BA89BD1CC1F821C03B969FF9D5C8B2F59666B6579736574584E81A6010102581D014A101D521D810211A0C6346BA89BD1CC1F821C03B969FF9D5C8B2F5903270481022006215820D59E31A5CD12E054BAF4CF8625AA6D810C93B91C0B28132FC09A8F3785CA45C6',
     {},
     h'D92711A400010178326D6166666261686B736477617165656E6179793267786B65333268676237617134616F3477743734356C7366733677696A70036B6C65646765722E696E666F05C11A64F0C821',
     h'6039815DB20A53207C407C82ED1481DAF2B09C2563058187052A45F905C0B54B377F699D45B0F0FC4819FD020603CCF2918670B30E58FE3DC653A78B85E86D08'
])

But unfortunately I get this error:

Error: Unauthorized to do this operation.

I'm sending as ID1 and can create tokens owned by ID1. I only get this when I try to create tokens owned by ID2. Any thoughts, @fmorency ?

@fmorency
Copy link
Contributor

Okay, I found and fixed a bug and the request seems to be correct now:

18([
     h'A3012704581D014A101D521D810211A0C6346BA89BD1CC1F821C03B969FF9D5C8B2F59666B6579736574584E81A6010102581D014A101D521D810211A0C6346BA89BD1CC1F821C03B969FF9D5C8B2F5903270481022006215820D59E31A5CD12E054BAF4CF8625AA6D810C93B91C0B28132FC09A8F3785CA45C6',
     {},
     h'D92711A400010178326D6166666261686B736477617165656E6179793267786B65333268676237617134616F3477743734356C7366733677696A70036B6C65646765722E696E666F05C11A64F0C821',
     h'6039815DB20A53207C407C82ED1481DAF2B09C2563058187052A45F905C0B54B377F699D45B0F0FC4819FD020603CCF2918670B30E58FE3DC653A78B85E86D08'
])

But unfortunately I get this error:

Error: Unauthorized to do this operation.

I'm sending as ID1 and can create tokens owned by ID1. I only get this when I try to create tokens owned by ID2. Any thoughts, @fmorency ?

This is expected for a network without the "Token Create Migration" active.

Local dev environments need to enable the "Token Create Migration".

I would suggest you enable

  1. Account Count Data Attribute
  2. Memo Migration
  3. Token Migration
  4. Token Create Migration

when starting your network. Simply remove the disabled lines for those entries.

You will need to comment the hash entry of the staging file if you're enabling those.

@stanleyjones
Copy link
Contributor Author

Okay, this is working now. I was assigning both the owner and the initial distribution address to the input address and it looks like the owner has to remain the sender.

Copy link
Contributor Author

@stanleyjones stanleyjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some hopefully useful comments.

queryKey: [neighborhood?.url, "tokens.info", address],
queryFn: async () => await neighborhood?.tokens.info({ address }),
enabled: !!neighborhood,
}))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just auto-formatting. No code changes.

Comment on lines -51 to +57
address: string;
amount: string;
destination: string;
name: string;
symbol: string;
owner: string;
precision?: number;
symbol: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sorted the arg list so the diff is a little messy, but I'm removing address and replacing it with both owner and destination. The former will be the same as the sender and the latter will take the input address.

}) =>
await neighborhood?.tokens.create({
summary: {
name,
symbol: symbol.toUpperCase(),
precision: 9,
precision,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

precision already defaulted to 9 so we don't need to hardcode a value here.

},
owner: address,
owner,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The owner parameter will now be set to the owner argument above...

distribution: {
[address]: BigInt(parseInt(amount) * 10 ** precision),
[destination]: BigInt(parseInt(amount) * 10 ** precision),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...while the destination of the initial distribution will be set to the destination argument.

rules={{
required: true,
validate: {
isManyAddress: (v) => new RegExp(/^m\w{24,}$/).test(v),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more accurate regex for detecting a valid Many address is welcome if we have one (I looked in the spec and many-rs).

@stanleyjones
Copy link
Contributor Author

@fmorency Okay, this one is ready now.

Copy link
Contributor

@fmorency fmorency left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still get an error when trying to create a token using the pre-populated destination field.

Copying and pasting the (same) address works.

2023-09-01_10-03

@stanleyjones
Copy link
Contributor Author

Okay, that's weird. I'll take a look.

@stanleyjones
Copy link
Contributor Author

Okay, fixed. Re-requesting reviews.

@stanleyjones
Copy link
Contributor Author

This is the CI error:

npm ERR! code ECONNRESET
npm ERR! errno ECONNRESET
npm ERR! network Invalid response body while trying to fetch https://registry.npmjs.org/jest-haste-map: aborted
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network 
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/circleci/.npm/_logs/2023-09-07T17_24_52_609Z-debug-0.log

Exited with code exit status 1

Going to rerun.

@fmorency fmorency merged commit 26510c9 into liftedinit:main Sep 11, 2023
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Token creation destination address should not be hardcoded
2 participants