Optional (or pre-filled) preimage length (#8497)

* Optional (or pre-filled) preimage length

* Adjust

* Adjust bot token usage
This commit is contained in:
Jaco 2022-12-07 15:47:05 +02:00 committed by GitHub
parent 5a78c180b7
commit 9a8b23854c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 84 additions and 18 deletions

View File

@ -17,15 +17,15 @@ jobs:
- uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e
with:
fetch-depth: 0
token: ${{ secrets.GH_PAT }}
token: ${{ secrets.GH_PAT_BOT }}
- name: ${{ matrix.step }}
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
CRUST_SEEDS: ${{ secrets.CRUST_SEEDS }}
GH_PAGES_SRC: packages/apps/build
GH_PAT: ${{ secrets.GH_PAT }}
GH_RELEASE_GITHUB_API_TOKEN: ${{ secrets.GH_PAT }}
GH_PAT: ${{ secrets.GH_PAT_BOT }}
GH_RELEASE_GITHUB_API_TOKEN: ${{ secrets.GH_PAT_BOT }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
PINATA_API_KEY: ${{ secrets.PINATA_API_KEY }}
PINATA_SECRET_KEY: ${{ secrets.PINATA_SECRET_KEY }}
@ -57,7 +57,7 @@ jobs:
steps:
- uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e
with:
token: ${{ secrets.GH_PAT }}
token: ${{ secrets.GH_PAT_BOT }}
- name: Prepare for app notarization (macOS)
if: startsWith(matrix.os, 'macos')
# Import Apple API key for app notarization on macOS

View File

@ -6,6 +6,7 @@
"The account you want to register the preimage from": "The account you want to register the preimage from",
"The amount reserved to store this image": "The amount reserved to store this image",
"The calculated storage costs based on the size and the per-bytes fee.": "The calculated storage costs based on the size and the per-bytes fee.",
"The encoded length of the selected proposal, as available on-chain": "The encoded length of the selected proposal, as available on-chain",
"The hash of the selected proposal, use it for submitting the proposal": "The hash of the selected proposal, use it for submitting the proposal",
"The image (proposal) will be stored on-chain against the hash of the contents.": "The image (proposal) will be stored on-chain against the hash of the contents.",
"This account will pay the fees for the preimage, based on the size thereof.": "This account will pay the fees for the preimage, based on the size thereof.",
@ -14,6 +15,7 @@
"count": "count",
"images": "images",
"preimage hash": "preimage hash",
"preimage length": "preimage length",
"preimages": "preimages",
"proposal": "proposal",
"propose": "propose",

View File

@ -31,9 +31,11 @@
"The moment of enactment, either at a specific block, or after a specific number of blocks.": "The moment of enactment, either at a specific block, or after a specific number of blocks.",
"The origin (and by extension track) that you wish to submit for, each has a different period, different root and acceptance criteria.": "The origin (and by extension track) that you wish to submit for, each has a different period, different root and acceptance criteria.",
"The preimage hash of the proposal": "The preimage hash of the proposal",
"The preimage length of the proposal": "The preimage length of the proposal",
"The proposal will be registered from this account and the balance lock will be applied here.": "The proposal will be registered from this account and the balance lock will be applied here.",
"The referendum this deposit would apply to.": "The referendum this deposit would apply to.",
"The transaction will be submitted from this account.": "The transaction will be submitted from this account.",
"The value will be populated when a valid on-chain hash exists in preimages": "The value will be populated when a valid on-chain hash exists in preimages",
"The vote will be recorded for this account. If another account delegated to this one, the delegated votes will also be counted.": "The vote will be recorded for this account. If another account delegated to this one, the delegated votes will also be counted.",
"Vote": "Vote",
"Vote Aye": "Vote Aye",
@ -45,6 +47,7 @@
"deposit from account": "deposit from account",
"preimage": "preimage",
"preimage hash": "preimage hash",
"preimage length": "preimage length",
"preimage {{shortHash}}": "preimage {{shortHash}}",
"propose from account": "propose from account",
"referenda": "referenda",

View File

@ -21,6 +21,7 @@ interface Props {
interface HashState {
encodedHash: string;
encodedLength: number;
encodedProposal: string;
storageFee: BN;
}
@ -32,12 +33,16 @@ function Add ({ className, imageHash }: Props): React.ReactElement<Props> {
const { api, apiDefaultTxSudo } = useApi();
const [isAddOpen, toggleAdd] = useToggle();
const [accountId, setAccountId] = useState<string | null>(null);
const [{ encodedHash, encodedProposal, storageFee }, setHash] = useState<HashState>({ encodedHash: ZERO_HASH, encodedProposal: '', storageFee: BN_ZERO });
const [{ encodedHash, encodedLength, encodedProposal, storageFee }, setHash] = useState<HashState>({ encodedHash: ZERO_HASH, encodedLength: 0, encodedProposal: '', storageFee: BN_ZERO });
const [proposal, setProposal] = useState<SubmittableExtrinsic<'promise'>>();
useEffect((): void => {
// get the proposal in hex format, i.e. we don't want the length prefix
const encodedProposal = (proposal as SubmittableExtrinsic<'promise'>)?.method.toHex() || '';
// we are dealing with hex values here, so subtrack the prefix (+ 2 chars per byte)
const encodedLength = Math.max(0, Math.round((encodedProposal.length - 2) / 2));
// we currently don't have a constant exposed, or rather, maybe somewhere else...
// const storageFee = api.consts.democracy.preimageByteDeposit.mul(
// encodedProposal
@ -45,7 +50,7 @@ function Add ({ className, imageHash }: Props): React.ReactElement<Props> {
// : BN_ZERO
// );
setHash({ encodedHash: blake2AsHex(encodedProposal), encodedProposal, storageFee: BN_ZERO });
setHash({ encodedHash: blake2AsHex(encodedProposal), encodedLength, encodedProposal, storageFee: BN_ZERO });
}, [api, proposal]);
const isMatched = imageHash
@ -95,6 +100,13 @@ function Add ({ className, imageHash }: Props): React.ReactElement<Props> {
label={t<string>('preimage hash')}
value={encodedHash}
/>
<Input
className='disabledLook'
help={t<string>('The encoded length of the selected proposal, as available on-chain')}
isDisabledError={!isMatched}
label={t<string>('preimage length')}
value={encodedLength.toString()}
/>
</Modal.Columns>
{!storageFee.isZero() && (
<Modal.Columns hint={t<string>('The calculated storage costs based on the size and the per-bytes fee.')}>

View File

@ -30,8 +30,13 @@ interface Props {
}
interface HashState {
hash?: HexString | null;
isHashValid: boolean;
imageHash?: HexString | null;
isImageHashValid: boolean;
}
interface ImageState {
imageLen: number;
isImageLenValid: boolean;
}
interface DefaultAtAfter {
@ -65,8 +70,9 @@ function Submit ({ className = '', isMember, members, palletReferenda, tracks }:
const [origin, setOrigin] = useState<RawParam['value'] | null>(null);
const [atAfter, setAtAfter] = useState<RawParam['value'] | null>(null);
const [defaultAtAfter, setDefaultAtAfter] = useState<DefaultAtAfter | null>(null);
const [{ hash, isHashValid }, setHash] = useState<HashState>({ hash: null, isHashValid: false });
const preimage = usePreimage(hash);
const [{ imageHash, isImageHashValid }, setImageHash] = useState<HashState>({ imageHash: null, isImageHashValid: false });
const [{ imageLen, isImageLenValid }, setImageLen] = useState<ImageState>({ imageLen: 0, isImageLenValid: false });
const preimage = usePreimage(imageHash);
useEffect((): void => {
trackId !== undefined && setDefaultAtAfter((prev) =>
@ -74,6 +80,10 @@ function Submit ({ className = '', isMember, members, palletReferenda, tracks }:
);
}, [trackId]);
useEffect((): void => {
preimage?.proposalLength && setImageLen({ imageLen: preimage?.proposalLength.toNumber(), isImageLenValid: true });
}, [preimage]);
const trackInfo = useMemo(
() => getTrackInfo(api, specName, palletReferenda, tracks, trackId),
[api, palletReferenda, specName, trackId, tracks]
@ -148,9 +158,31 @@ function Submit ({ className = '', isMember, members, palletReferenda, tracks }:
[]
);
const _onChangeHash = useCallback(
(hash?: string) =>
setHash({ hash: hash as HexString, isHashValid: isHex(hash, 256) }),
const _onChangeImageHash = useCallback(
(h?: string) =>
setImageHash({
imageHash: h as HexString,
isImageHashValid: isHex(h, 256)
}),
[]
);
const _onChangeImageLen = useCallback(
(l?: string): void => {
try {
const imageLen = Number.parseInt(l || '0', 10);
setImageLen({
imageLen,
isImageLenValid: Number.isInteger(imageLen)
});
} catch {
setImageLen({
imageLen: 0,
isImageLenValid: false
});
}
},
[]
);
@ -183,10 +215,19 @@ function Submit ({ className = '', isMember, members, palletReferenda, tracks }:
<Input
autoFocus
help={t<string>('The preimage hash of the proposal')}
isError={!isHashValid}
isError={!isImageHashValid}
label={t<string>('preimage hash')}
onChange={_onChangeHash}
value={hash}
onChange={_onChangeImageHash}
value={imageHash || ''}
/>
</Modal.Columns>
<Modal.Columns hint={t<string>('The value will be populated when a valid on-chain hash exists in preimages')}>
<Input
help={t<string>('The preimage length of the proposal')}
key='inputLength'
label={t<string>('preimage length')}
onChange={_onChangeImageLen}
value={imageLen.toString()}
/>
</Modal.Columns>
<Modal.Columns hint={t<string>('The origin (and by extension track) that you wish to submit for, each has a different period, different root and acceptance criteria.')}>
@ -243,10 +284,18 @@ function Submit ({ className = '', isMember, members, palletReferenda, tracks }:
<TxButton
accountId={accountId}
icon='plus'
isDisabled={!selectedOrigin || !atAfter || !isHashValid || !accountId || isInvalidAt || !preimage?.proposalHash}
isDisabled={!selectedOrigin || !atAfter || !isImageHashValid || !isImageLenValid || !accountId || isInvalidAt || !preimage?.proposalHash}
label={t<string>('Submit proposal')}
onStart={toggleSubmit}
params={[selectedOrigin, { Lookup: { hash: preimage?.proposalHash, len: preimage?.proposalLength } }, atAfter]}
params={[
selectedOrigin,
{
Lookup: preimage
? { hash: preimage.proposalHash, len: imageLen }
: { hash: imageHash, len: imageLen }
},
atAfter
]}
tx={api.tx[palletReferenda as 'referenda'].submit}
/>
</Modal.Actions>