Skip to content
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

Adding multisig wallet #354

Open
wants to merge 24 commits into
base: multisig-wallet
Choose a base branch
from

Conversation

rodendron-xrhodium
Copy link

This should provide multisig wallet features:

  1. New wallet creation
  2. Address creation
  3. Storage synch with chain
  4. Transaction creation
  5. Partially signed transaction broadcast?

@dangershony
Copy link
Member

Excellent job, any chance you can add a step by step how to make a multisig between 3 participants?

@rodendron-xrhodium
Copy link
Author

Created a small issue documenting the process as requested. #357 please let me know if you have questions/comments on things that were not sufficiently clear.

@rodendron-xrhodium rodendron-xrhodium changed the title WIP (Work in progress) Adding multisig wallet Adding multisig wallet Oct 14, 2021
@dangershony
Copy link
Member

I will try to review this today

Copy link
Member

@dangershony dangershony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first review.
I think my main concern is not to make too much changes to the current wallet mainly because all though we have many tests there is still so much complexity involved, the wallet has grown really big and we should try to break components out not add to it, the best would be if this would be its own feature though I am aware it will probably be harder to implement and more work.

We should still consider this because breaking anything in the wallet can effect many chains, staking, cold staking and mining.

/// <returns>(string) Hex string of the transaction</returns>
[ActionName("createrawtransaction")]
[ActionDescription("Create a transaction spending the given inputs and creating new outputs. Outputs can be addresses or data. Returns hex - encoded raw transaction. Note that the transaction's inputs are not signed, and it is not stored in the wallet or transmitted to the network.")]
public IActionResult CreateRawTransaction(string inputs, string outputs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why use strings instead of an object?

@@ -151,6 +154,239 @@ public async Task<uint256> SendToAddressAsync(BitcoinAddress address, decimal am
}
}

/// <summary>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to create a new controller for the multisig methods

if (wallet.IsMultisig)
{
// Add keys for signing inputs. This takes time so only add keys for distinct addresses.
foreach (UnspentOutputReference unspentOutput in this.walletManager.GetSpendableTransactionsInWallet(accountReference.WalletName, 1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will take all spendable outputs is that the intention? don't you want to get outptus by amount?
I assume this method started the multisig processes and populates inputs, it looks like you just take all outputs from a wallet


[ActionName("combinemultisigsignatures")]
[ActionDescription("Combines multiple signed (same) transctions into 1 properly signed transaction")]
public IActionResult CombineMultisigSignatures(string transactions)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its a very good idea to look at PSBT even if we need to add a reference to the current NBitcoin repo (they have PSBT) that will really simplify moving trx between clients

return this.Json(wallet);
}

[ActionName("combinemultisigsignatures")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are missing comments here so its hard to know what is the intention of this method

@@ -55,6 +55,7 @@ public class WalletManager : IWalletManager
/// <summary>File extension for wallet files.</summary>
private const string WalletFileExtension = "wallet.json";

private const string WalletMultisigFileExtension = "multisigwallet.json";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting approach, so we will have a new wallet file for multisig wallets hmmm...
Perhaps this is a good solution that has the least changes made to the current wallet code (without multisig)

We have to also remember that cold staking is doing some method overrides in the cold stake feature


return wallet;
}
private static string GetWalletFileName(WalletMultisig wallet)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetMultisigWalletFileName?


/// <summary>Filter for all wallet accounts.</summary>
public static Func<HdAccount, bool> AllAccounts = a => true;
public static Func<IHdAccount, bool> AllAccounts = a => true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly this PR would be much easier to review if the interfaces over account and address was not created, is that really necessary?

@@ -29,6 +29,7 @@
<ItemGroup>
<ProjectReference Include="..\..\Features\Blockcore.Features.Wallet\Blockcore.Features.Wallet.csproj" />
<ProjectReference Include="..\..\Features\Blockcore.Features.RPC\Blockcore.Features.RPC.csproj" />
<ProjectReference Include="..\..\Networks\Blockcore.Networks.XRC\Blockcore.Networks.XRC.csproj" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a specific network is the wrong approach, it should be generic, network agnostic

[Fact]
public void Generate4SequnetialMultisigRecievingAndChangeAddress()
{
string[] receiving = { "rbAxG3vTMCuVMWppaobvTajBtUHSiFtkr5", "roLKXofxDFrkZqW7kU9aD7j7E6pTajEe16", "rjmcR79w6MatNK3KeHR3FvaEEHngdAKa9h", "reD6MyXPFUaJpyBtJVDgdYf7iN4qHbhzBz" };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you added the network in order to use the address format for XRC ok that is acceptable

@dimsavva
Copy link
Contributor

Anyone still working on this PR? Would be great to have multisig available.

@dangershony
Copy link
Member

@dimsavva this is a complicated PR hopefully we will get there

@dimsavva
Copy link
Contributor

Is there any way that I can help?

@sondreb
Copy link
Member

sondreb commented May 1, 2022

Is there any way that I can help?

Yes, test and verify and write some easy instructions on how to replicate / setup so I can also test it. We also need some instructions for users that could be added to the documentation repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants