-
Notifications
You must be signed in to change notification settings - Fork 8
fix: #60, Check if preimage exists on chain before creating a proposal #61
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ export async function tipOpenGov(opts: { | |
| ]); | ||
| const encodedProposal = proposalTx.method.toHex(); | ||
| const proposalHash = blake2AsHex(encodedProposal); | ||
| const encodedLength = Math.ceil((encodedProposal.length - 2) / 2); | ||
|
|
||
| return await new Promise(async (resolve, reject) => { | ||
| // create a preimage from opengov with the encodedProposal above | ||
|
|
@@ -57,7 +58,7 @@ export async function tipOpenGov(opts: { | |
| .submit( | ||
| // TODO: There should be a way to set those types properly. | ||
| { Origins: track.track } as never, | ||
| { Lookup: { hash: proposalHash, length: proposalTx.length - 1 } }, | ||
| { Lookup: { hash: proposalHash, len: encodedLength } }, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Here's some logs when I create it, in polkadotjs it shows 85
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just added 5 chars to a remark, and got 90 as final size in polkadotjs so it means to me all 3 will give same correct size of preimage I just used last as this is most commonly used
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay yea then just use what works. The TS code is fucked either way. |
||
| { after: 10 } as never, | ||
| ) | ||
| .signAndSend(botTipAccount, { nonce: -1 }, async (refResult) => { | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this calculation? It needs to be the SCALE encoded length.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before it was
proposalTx.length - 1, but this I took from https://github.com/polkadot-js/apps/blob/2d295e33f9d37d6582d97b9e93df81d16e1950e2/packages/page-preimages/src/Preimages/Add/Partial.tsx#L44@ggwpez could you please explain what is SCALE encoded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It first does
toHexand then uses(x - 2) / 2to get the number of bytes in the hex string… wtfMaybe there is no easier way to encode it or something. Ideal would be an
encodeorencodedLengthfunction.Otherwise just add a test; i dont want to block over this if it works.
SCALE is the encoding that Substrate/Polkadot uses for mostly everything. Especially stuff like transactions and their arguments (so also preimages).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll investigate and we will add tests for sure