Skip to content

Commit

Permalink
Merge pull request #4426 from mnaamani/carthage-cli-multisig
Browse files Browse the repository at this point in the history
Carthage cli multisig fixes
  • Loading branch information
mnaamani authored Nov 10, 2022
2 parents d224372 + af1d7c8 commit 8a59c6e
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 39 deletions.
4 changes: 3 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"@polkadot/keyring": "9.5.1",
"@polkadot/util": "9.5.1",
"@polkadot/util-crypto": "9.5.1",
"@substrate/txwrapper-polkadot": "3.2.2",
"@substrate/txwrapper-core": "3.1.3",
"@substrate/txwrapper-substrate": "3.1.3",
"@substrate/txwrapper-polkadot": "3.1.3",
"@types/cli-progress": "^3.9.1",
"@types/fluent-ffmpeg": "^2.1.16",
"@types/inquirer": "^6.5.0",
Expand Down
14 changes: 4 additions & 10 deletions cli/src/base/AdvancedTransactionsCommandBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export default abstract class AdvancedTransactionsCommandBase extends AccountsCo
}

if (argsInput.maxWeight.toString() !== args.maxWeight.toString()) {
this.warn(`"maxWeight" changed from ${argsInput.maxWeight} to ${args.maxWeight} .`)
this.warn(`"maxWeight" changed from ${argsInput.maxWeight} to ${args.maxWeight}.`)
}
return args
}
Expand All @@ -158,20 +158,14 @@ export default abstract class AdvancedTransactionsCommandBase extends AccountsCo
): Promise<MultisigAsMulti> {
if (input) {
const args = await this.getAsMultiInputFromFile(input)
const originalArgs = { ...args }
const otherSignatories = args.otherSignatories as string[]
const otherSignatoriesSorted = sortAddresses(otherSignatories, JOYSTREAM_ADDRESS_PREFIX)
const signatoriesChanged = !otherSignatoriesSorted.every(
(signatory, index) => signatory === otherSignatories[index]
)
args.otherSignatories = otherSignatoriesSorted
const maxWeightChanged = maxWeight !== (args.maxWeight as number)
args.maxWeight = maxWeight
if (signatoriesChanged || maxWeightChanged) {
await this.requireConfirmation(
`Some file inputs have been overridden:` + `args from file input: ${originalArgs}` + `new args: ${args}`
)
if (maxWeightChanged) {
this.warn(`"maxWeight" changed from ${args.maxWeight} to ${maxWeight}.`)
}
args.maxWeight = maxWeight
return args
} else if (threshold && others && timepointHeight && timepointIndex) {
const otherSignatories = sortAddresses(others.split(','), JOYSTREAM_ADDRESS_PREFIX)
Expand Down
13 changes: 9 additions & 4 deletions cli/src/base/SignOfflineCommandBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { Keyring } from '@polkadot/api'
import { getInputJson } from '../helpers/InputOutput'
import { KeyringPair } from '@polkadot/keyring/types'
import { GenericExtrinsicPayload, GenericExtrinsicPayloadV4 } from '@polkadot/types'
import { waitReady } from '@polkadot/wasm-crypto'
// import { waitReady } from '@polkadot/wasm-crypto'
import { initWasm } from '@polkadot/wasm-crypto/initOnlyAsm'
import { JOYSTREAM_ADDRESS_PREFIX, registry } from '@joystream/types'
import inquirer from 'inquirer'
import { DecodedSigningPayload } from '@substrate/txwrapper-core'
Expand All @@ -22,15 +23,15 @@ export default abstract class SignOfflineCommandBase extends StateAwareCommandBa
}

async createPayload(signingPayload: string): Promise<GenericExtrinsicPayload> {
await waitReady()
await initWasm()
const payload = registry.createType('ExtrinsicPayload', signingPayload, {
version: 4,
})
return payload
}

async createPayloadV4(signingPayload: string): Promise<GenericExtrinsicPayloadV4> {
await waitReady()
await initWasm()
const payload = registry.createType('ExtrinsicPayloadV4', signingPayload)
return payload
}
Expand Down Expand Up @@ -72,7 +73,11 @@ export default abstract class SignOfflineCommandBase extends StateAwareCommandBa
} has approved already), you need to construct the unsigned transaction again with 'constructUnsignedTxApproveMs'`
)
}
this.log(`the encoded call ${multisigTxData.call}`)
if (multisigTxData.call.length < 500) {
this.log(`the call ${multisigTxData.call}`)
} else {
this.log(`the call is to too long for log. Check the output file.`)
}
} else {
this.error(
`The callHash you want to approve: ${args.callHash.toString()} n\` ` +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { blake2AsHex } from '@polkadot/util-crypto'
import { registry } from '@joystream/types'

export default class CreateSetCodeCallCommand extends AdvancedTransactionsCommandBase {
static description = 'Construct a wrapped transaction call.'
static description = 'Construct a "system.setCode" call.'
static flags = {
wasmPath: flags.string({
required: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,13 @@ export default class ConstructUnsignedTxApproveMsCommand extends AdvancedTransac
` - free: ${formatBalance(accBalances[0].freeBalance)}\n` +
` - available: ${formatBalance(accBalances[0].availableBalance)}\n` +
`If the multisig approves, the transaction will execute:\n` +
` - module:method - ${decodedCall.section}:${decodedCall.method}\n` +
` - ${decodedCall.argsEntries.toString()}\n`
` - module:method - ${decodedCall.section}:${decodedCall.method}\n`
)
if (decodedCall.argsEntries.toString().length < 500) {
this.log(` - ${decodedCall.argsEntries.toString()}\n`)
} else {
this.log(`Decoded call is to too long for log. Check the output file.`)
}

const multisigTxData = {
call,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,26 @@ export default class ConstructUnsignedTxFinalApproveMsCommand extends AdvancedTr
const accBalances = await this.getApi().getAccountsBalancesInfo([multiAddress])

if (addressMs) {
this.log(
`You are approving a multisig transaction from ${multiAddress}, with balances:\n` +
` - free: ${formatBalance(accBalances[0].freeBalance)}\n` +
` - available: ${formatBalance(accBalances[0].availableBalance)}\n` +
`If the multisig approves, the transaction will execute:\n` +
` - module:method - ${decodedCall.section}:${decodedCall.method}\n` +
` - ${decodedCall.argsEntries.toString()}\n`
)
if (multiAddress !== addressMs) {
await this.requireConfirmation(
`The input sender account, addressMs: ${addressMs},` +
`does not match the account calculated from signer + others: ${multiAddress}` +
`Do you wish to continue?`
)
}
}

this.log(
`You are approving (as the final signer required) a multisig transaction from ${multiAddress}, with balances:\n` +
` - free: ${formatBalance(accBalances[0].freeBalance)}\n` +
` - available: ${formatBalance(accBalances[0].availableBalance)}\n` +
`If the multisig approves, the transaction will execute:\n` +
` - module:method - ${decodedCall.section}:${decodedCall.method}\n`
)
if (decodedCall.argsEntries.toString().length < 500) {
this.log(` - ${decodedCall.argsEntries.toString()}\n`)
} else {
this.log(`Decoded call is to too long for log. Check the output file.`)
}

const multisigTxData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,13 @@ export default class ConstructUnsignedTxInitiateMsCommand extends AdvancedTransa
` - free: ${formatBalance(accBalances[0].freeBalance)}\n` +
` - available: ${formatBalance(accBalances[0].availableBalance)}\n` +
`If the multisig approves, the transaction will execute:\n` +
` - module:method - ${decodedCall.section}:${decodedCall.method}\n` +
` - ${decodedCall.argsEntries.toString()}\n`
` - module:method - ${decodedCall.section}:${decodedCall.method}\n`
)
if (decodedCall.argsEntries.toString().length < 500) {
this.log(` - ${decodedCall.argsEntries.toString()}\n`)
} else {
this.log(`Decoded call is to too long for log. Check the output file.`)
}

const multisigTxData = {
call,
Expand Down
7 changes: 4 additions & 3 deletions cli/src/commands/sign-offline/signUnsignedTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import { IOFlags, ensureOutputFileIsWriteable, getInputJson, saveOutputJsonToFil
import { decodeSignedTx } from '@substrate/txwrapper-core/lib/core/decode/decodeSignedTx'
import { decodeSigningPayload } from '@substrate/txwrapper-core/lib/core/decode/decodeSigningPayload'
import { Keyring } from '@polkadot/api'
import { waitReady } from '@polkadot/wasm-crypto'
// import { waitReady } from '@polkadot/wasm-crypto'
import { initWasm } from '@polkadot/wasm-crypto/initOnlyAsm'
import { KeyringOptions, KeyringPair, KeyringPair$Json } from '@polkadot/keyring/types'
import { createSignedTx, getTxHash } from '@substrate/txwrapper-core/lib/core/construct'
import { KeypairType } from '@polkadot/util-crypto/types'
import { DEFAULT_ACCOUNT_TYPE } from '../../base/AccountsCommandBase'
import { u8aToHex } from '@polkadot/util'

export default class SignUnsignedTxCommand extends SignOfflineCommandBase {
static description = 'Transfer tokens from any of the available accounts'
static description = 'Sign an unsigned transaction. Does not require an api connection.'
static flags = {
input: IOFlags.input,
output: flags.string({
Expand Down Expand Up @@ -111,7 +112,7 @@ export default class SignUnsignedTxCommand extends SignOfflineCommandBase {
}

const metadata = inputFile.unsigned.metadataRpc.slice(2)
await waitReady()
await initWasm()

const signingPayloadDecoded = decodeSigningPayload(inputFile.signingPayload, {
metadataRpc: `0x${metadata}`,
Expand Down
31 changes: 23 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3198,23 +3198,38 @@
resolved "https://registry.yarnpkg.com/@substrate/ss58-registry/-/ss58-registry-1.22.0.tgz#d115bc5dcab8c0f5800e05e4ef265949042b13ec"
integrity sha512-IKqrPY0B3AeIXEc5/JGgEhPZLy+SmVyQf+k0SIGcNSTqt1GLI3gQFEOFwSScJdem+iYZQUrn6YPPxC3TpdSC3A==

"@substrate/txwrapper-core@^3.2.2":
"@substrate/txwrapper-core@3.1.3":
version "3.1.3"
resolved "https://registry.yarnpkg.com/@substrate/txwrapper-core/-/txwrapper-core-3.1.3.tgz#ec790e332dd09ee5021b3824b43f11b0fc70f36a"
integrity sha512-8QV5wp+V1/KXu/f2K9uTfbBrEXiu86z1N/O6+4858hYGihypZuO2YT0pChfsnj0Uic4K2T2QDzTCj8VJ70yORA==
dependencies:
"@polkadot/api" "8.9.1"
memoizee "0.4.15"

"@substrate/txwrapper-core@^3.1.3", "@substrate/txwrapper-core@^3.2.2":
version "3.2.2"
resolved "https://registry.yarnpkg.com/@substrate/txwrapper-core/-/txwrapper-core-3.2.2.tgz#55825ff84bd4cd95fa2f869111616300f66db513"
integrity sha512-Wj6odIvu69YC7RbxAPRllm48bZhK3nyygw1jRSZLzp/gfIzOAYz8KYvVtm62ZtmKKhs9jggD/H0SO+Nn37N0DA==
dependencies:
"@polkadot/api" "9.3.3"
memoizee "0.4.15"

"@substrate/txwrapper-polkadot@3.2.2":
version "3.2.2"
resolved "https://registry.yarnpkg.com/@substrate/txwrapper-polkadot/-/txwrapper-polkadot-3.2.2.tgz#cb390756f53e277b58582d5643b1326636733b84"
integrity sha512-bx+RnRZWfX8hNIWzhOoNZo63A7gZT6/zu2J3Yu76lBebBloWfaX9PInLWdvRvdRDI1R30WGrESefhFuTILVguQ==
"@substrate/txwrapper-polkadot@3.1.3":
version "3.1.3"
resolved "https://registry.yarnpkg.com/@substrate/txwrapper-polkadot/-/txwrapper-polkadot-3.1.3.tgz#34c4ad1eaba72f829a8935846503ab15a412f011"
integrity sha512-uP48AuHlKjTz6EZzvlIVe7WnKu3xhacJFrVO0pAHZcnFxm/IVLhAItqN8KLd3xZmbIpy4Zlw9nITM+iaDU/ljA==
dependencies:
"@substrate/txwrapper-core" "^3.2.2"
"@substrate/txwrapper-substrate" "^3.2.2"
"@substrate/txwrapper-core" "^3.1.3"
"@substrate/txwrapper-substrate" "^3.1.3"

"@substrate/txwrapper-substrate@3.1.3":
version "3.1.3"
resolved "https://registry.yarnpkg.com/@substrate/txwrapper-substrate/-/txwrapper-substrate-3.1.3.tgz#81dd8a9a9780f291c3cf111a49c370829f75e975"
integrity sha512-v8skSLC40axHJN/dg51wLEAnQxk/5tk/EWr6rBKLFM4T8Kmjirj83lLyzVhRNRVYWdgCAr6Maoe+v1CWNXKoXw==
dependencies:
"@substrate/txwrapper-core" "^3.1.3"

"@substrate/txwrapper-substrate@^3.2.2":
"@substrate/txwrapper-substrate@^3.1.3":
version "3.2.2"
resolved "https://registry.yarnpkg.com/@substrate/txwrapper-substrate/-/txwrapper-substrate-3.2.2.tgz#ac736d2f617736231609fcf6f19b7393051cb00b"
integrity sha512-kTLgw3TeKVVxfL6eQgPm3ltlcxxxBH9u8CfuEQHa1EmGuL5RyW11JYHDJU5jFbK+8euADZK8Oo7Uo1txXocIUw==
Expand Down

0 comments on commit 8a59c6e

Please sign in to comment.