-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added doc extrinsic examples for as_multi and approving_as_multi
- Loading branch information
1 parent
1d7d426
commit f3d456d
Showing
6 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { SDK, WaitFor, Keyring } from "./../../src/index" | ||
|
||
const main = async () => { | ||
const providerEndpoint = "ws://127.0.0.1:9944" | ||
const sdk = await SDK.New(providerEndpoint) | ||
|
||
// Multisig Signatures | ||
const alice = new Keyring({ type: "sr25519" }).addFromUri("//Alice") | ||
const bobAddress = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" | ||
|
||
// Create Multisig Account | ||
const threshold = 2 | ||
const multisigAddress = sdk.util.generateMultisig([alice.address, bobAddress], threshold) | ||
|
||
// Define what action will be taken by the multisig account | ||
const amount = SDK.oneAvail() | ||
const call = sdk.api.tx.balances.transferKeepAlive(multisigAddress, amount) | ||
// Data needed for multisig approval and execution | ||
const callHash = call.method.hash.toString() | ||
const maxWeight = (await call.paymentInfo(alice.address)).weight | ||
|
||
// Create New Multisig | ||
console.log("Alice is creating a Multisig Transaction...") | ||
const call1signatures = sdk.util.sortMultisigAddresses([bobAddress]) | ||
const result = await sdk.tx.multisig.approveAsMulti( | ||
threshold, | ||
call1signatures, | ||
null, | ||
callHash, | ||
maxWeight, | ||
WaitFor.BlockInclusion, | ||
alice, | ||
) | ||
if (result.isErr()) { | ||
console.log(result.error) | ||
process.exit(1) | ||
} | ||
|
||
console.log(JSON.stringify(result.value, null, 2)) | ||
process.exit() | ||
} | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { SDK, WaitFor, Keyring, MultisigTimepoint } from "./../../src/index" | ||
|
||
const main = async () => { | ||
const providerEndpoint = "ws://127.0.0.1:9944" | ||
const sdk = await SDK.New(providerEndpoint) | ||
|
||
// Multisig Signatures | ||
const bob = new Keyring({ type: "sr25519" }).addFromUri("//Bob") | ||
const aliceAddress = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" | ||
|
||
// Create Multisig Account | ||
const threshold = 2 | ||
const multisigAddress = sdk.util.generateMultisig([aliceAddress, bob.address], threshold) | ||
|
||
// Define what action will be taken by the multisig account | ||
const amount = SDK.oneAvail() | ||
const call = sdk.api.tx.balances.transferKeepAlive(multisigAddress, amount) | ||
// Data needed for multisig approval and execution | ||
const callData = call.unwrap().toHex() | ||
const maxWeight = (await call.paymentInfo(aliceAddress)).weight | ||
const timepoint: MultisigTimepoint = { height: 4, index: 1 } | ||
|
||
// Approving and executing Multisig transaction | ||
console.log("Bob is approving and executing the existing Multisig Transaction...") | ||
const call2signatures = sdk.util.sortMultisigAddresses([aliceAddress]) | ||
const secondResult = await sdk.tx.multisig.asMulti( | ||
threshold, | ||
call2signatures, | ||
timepoint, | ||
callData, | ||
maxWeight, | ||
WaitFor.BlockInclusion, | ||
bob, | ||
) | ||
if (secondResult.isErr()) { | ||
console.log(secondResult.error) | ||
process.exit(1) | ||
} | ||
|
||
console.log(JSON.stringify(secondResult.value, null, 2)) | ||
process.exit() | ||
} | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters