-
Notifications
You must be signed in to change notification settings - Fork 1k
[Add] Multi-Sig Support in Wallets
#4213
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 8 commits
77c1719
c6c5df1
c82731f
7899613
ff491dd
42fccae
3394cc6
18c349a
294d9a9
9a13abe
0213299
c1faf3a
96dbcb1
58f8059
bae6d8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,6 +136,53 @@ protected Wallet(string path, ProtocolSettings settings) | |
| Path = path; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Constructs a special contract with empty script, will get the script with | ||
| /// scriptHash from blockchain when doing the verification. | ||
| /// <code> | ||
| /// Note: | ||
| /// Creates "m" out of "n" type verification script using <paramref name="publicKeys"/> length | ||
| /// with the default BFT assumptions of Ceiling(n - (n-1) / 3) for "m". | ||
| /// </code> | ||
| /// </summary> | ||
| /// <param name="publicKeys">The public keys of the contract.</param> | ||
| /// <returns>Multi-Signature contract <see cref="WalletAccount"/>.</returns> | ||
| /// <exception cref="ArgumentOutOfRangeException"> | ||
| /// <paramref name="publicKeys" /> is empty. | ||
| /// </exception> | ||
| /// <seealso cref="CreateMultiSigAccount(int, ECPoint[])"/> | ||
| public WalletAccount CreateMultiSigAccount(params ECPoint[] publicKeys) => | ||
| CreateMultiSigAccount(1, publicKeys); | ||
cschuchardt88 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// <summary> | ||
| /// Constructs a special contract with empty script, will get the script with | ||
| /// scriptHash from blockchain when doing the verification. | ||
| /// </summary> | ||
| /// <param name="m">The number of correct signatures that need to be provided in order for the verification to pass.</param> | ||
| /// <param name="publicKeys">The public keys of the contract.</param> | ||
| /// <returns>Multi-Signature contract <see cref="WalletAccount"/>.</returns> | ||
| /// <exception cref="ArgumentOutOfRangeException"> | ||
| /// <paramref name="publicKeys" /> is empty or <paramref name="m"/> is greater than <paramref name="publicKeys"/> length or | ||
| /// <paramref name="m"/> is less than 1 or <paramref name="m"/> is greater than 1024. | ||
| /// </exception> | ||
| /// <seealso cref="CreateMultiSigAccount(ECPoint[])"/> | ||
| public WalletAccount CreateMultiSigAccount(int m, params ECPoint[] publicKeys) | ||
| { | ||
| ArgumentOutOfRangeException.ThrowIfEqual(publicKeys.Length, 0, nameof(publicKeys)); | ||
| ArgumentOutOfRangeException.ThrowIfGreaterThan(m, publicKeys.Length, nameof(publicKeys)); | ||
| ArgumentOutOfRangeException.ThrowIfLessThan(m, 1, nameof(m)); | ||
| ArgumentOutOfRangeException.ThrowIfGreaterThan(m, 1024, nameof(m)); | ||
|
|
||
| var contract = Contract.CreateMultiSigContract(m, publicKeys); | ||
| var account = GetAccounts().FirstOrDefault( | ||
|
||
| f => | ||
| f.HasKey && | ||
| f.Lock == false && | ||
| publicKeys.Contains(f.GetKey().PublicKey)); | ||
|
|
||
| return CreateAccount(contract, account?.GetKey()); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a standard account for the wallet. | ||
| /// </summary> | ||
|
|
@@ -237,6 +284,12 @@ public WalletAccount CreateAccount(Contract contract, byte[] privateKey) | |
| return result; | ||
| } | ||
|
|
||
| public IEnumerable<WalletAccount> GetMultiSigAccounts() => | ||
| GetAccounts() | ||
| .Where(static w => | ||
| w.Lock == false && | ||
| IsMultiSigContract(w.Contract.Script)); | ||
|
|
||
| /// <summary> | ||
| /// Gets the account with the specified public key. | ||
| /// </summary> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.