Closed Abhikjk closed 6 years ago
If you have P2SH, the coins should be ScriptCoin
instances where the Redeem is included.
Actually i am getting the coins from other addresses by loop through balance model of qbitninza getbalance() method, i tried by creating a fake transaction with coins of the same and then creating my actual sending transaction with the coins of fake transaction its buulding fine and verified as well but not sending the amount in reality, Please suggest
I advise you against using HD with QBitNinja it is quite hard. Check https://programmingblockchain.gitbooks.io/programmingblockchain/content/wallet/web-api.html which rely on NBXplorer. You need your own bitcoin full node but it makes it quite easy to have HD wallet, including multi sig one.
Nic,As I have already implemented BIP32 with NBitCoin KeyDerivation functionality and creating adresses from the masterWallet extended key like below: string Address=masterWalletExtKey.Neuter().Derive(new KeyPath(Convert.ToString(ChainDerivationKey))).PubKey.GetAddress(Network.TestNet).ToString();
The above generated address is not multisig address ,So I am thinking ,will it be possible to make this address a multisig address? I dont want to use NBXplorer because the approach i have implemented is working fine with this BIP32 and our client is not going to give us the time to re-implement the whole process which is looking to take much of time. Please help me. Thanks
You need to derive the pubkeys on all ExtPubKeys, then use what is documented here.
You can get the P2SH address by using scriptPubKey = scriptPubkey.Hash.ScriptPubKey
, or better, the P2SH-Segwit by using scriptPubKey = scriptPubKey.WitHash.ScriptPubKey.Hash.ScriptPubKey
.
Then you can get that as an address with scriptPubKey.GetDestinationAddress(Network.Main)
In our scenario there is only one ExtPubKey,Please take a look below how we are generating the addresses: address = masterWallet.Neuter().Derive(new KeyPath (Convert.ToString(chainDerivationKey, CultureInfo.CurrentCulture))) .PubKey.GetAddress(Network.TestNet).ToString();
In above code
masterWallet is a ExtKey as defined below: internal ExtKey GetMasterWallet() { StringBuilder trace = null; try { trace = new StringBuilder(); trace.AppendLine("Start GetMasterWallet() in MasterWalletService"); var masterKey = new BTCWalletService(_unitOfWork).GetRootKey(); string root = "0'/"; string Adminroot = "0'/"; string keypath = new StringBuilder().Append(root).Append(Adminroot).ToString(); return masterKey.Derive(new KeyPath(keypath)); } catch (Exception ex) {
throw;
}
finally
{
trace.AppendLine("End GetMasterWallet() in MasterWalletService");
Logger.Info(Convert.ToString(trace));
}
}
and in above method masterKey is defined below:
public ExtKey GetRootKey()
{
StringBuilder trace = null;
ExtKey resultExtKey = null;
try
{
trace = new StringBuilder();
trace.AppendLine("Start GetRootKey() in BTCWalletService");
var mnemonicCode = _unitOfWork.MnemonicCodeRepository.Get().FirstOrDefault();
byte[] salt = System.Text.Encoding.Unicode.GetBytes(mnemonicCode.CreatedDate.ToString(CultureInfo.CurrentCulture));
var passphrase = SecurityEncription.Instance.SHA256Digest60K(Constant.passPhrase);
var decryptedMnemonic = SecurityEncription.Instance.AESDecrypt(mnemonicCode.MnemoCode, passphrase, salt);
resultExtKey = new Mnemonic(decryptedMnemonic, Wordlist.English).DeriveExtKey(passphrase);
}
catch(Exception ex)
{
Logger.Error(ex.Message, ex);
}
finally
{
trace.AppendLine("End GetRootKey() in BTCWalletService");
Logger.Info(Convert.ToString(trace));
trace = null;
}
return resultExtKey;
}
Will i need to create three masterwallet ExtKey?
Hi Nic, I succeeded in creating multisig address but unfortunately when going to build the transaction its throwing error "The redeem provided does not match the scriptPubKey of the coin"
Please help
Hi Nic, The above problem has been resolved but now at broadcast time its not broadcasting properly i think OR may be transaction problem,Please look at below transaction that is finally created after build process but no amount is transferred The built transaction is:
{{ "hash": "c3973f85cb332c031188af2292cb409a27c5fb9a31bbf8a4d0d421123661094d", "ver": 1, "vin_sz": 1, "vout_sz": 2, "lock_time": 0, "size": 478, "in": [ { "prev_out": { "hash": "4c3c832651ef78b40f9828f32114de32ffffe951210506d40df858dc61c70957", "n": 1 }, "scriptSig": "00207a1ced7a423c160de82476958aadc5e37e53c2bdea484c1ecb5ec0095241eccb", "witness": "0 304402202131cabe080936e71188c3ae4a9d74f3a0a5f1cf36386db46811b9f9ee7564bd02202e85a117a72ffc7afef29016a437fe8ae63326ec7d93c870e12077b7f01e303401 3045022100db3f21000a63fc3038e0e4408101b7eef0ecbfc98b0a168a2463e33c8190ccca02203e3707fcd401dee64e07b7532b6708fdd3f97bc232fa26c9fe21bd7d768d9f2701 3045022100844ea9c38588d506cb0a09b6d768b65567f86ef0ebf628619ea665ce9e6dc6ff02202e81c400a874362ec187a2d4c1e018743d86c85d2b6e8a95dd7558bfedac41a901 532103a49de10f94f503f51ba7785d5419d79d127726bb921bc646f4d1d579d2b0107221024699edf1996f54e698d53e6b57463eb96d9ea52522688a4dacdba4638835ac45210329c159fada835003a89bb06dcabb61fd8617ba09294568644a0c390756897a2b53ae" } ], "out": [ { "value": "0.69447109", "scriptPubKey": "OP_HASH160 dada67e42c94e7ada6df3bcffa7462f98c0aba80 OP_EQUAL" }, { "value": "0.00100000", "scriptPubKey": "OP_HASH160 6e907a596d5b95e91e2ffde01d72dee43410abb8 OP_EQUAL" } ] }}
Result of broadcast is -> ErrorOnBroadcastMultisig.docx Please look in attached word file
Sorry for bothering you :)
Hi Nic, When i tried with _rpcClient.SendRawTransaction(objCustomTransactionHistory.Tranasction); It succeeded,Could you give me reason,Because when we go with MainNet it was working fine with QbitNinja Broadcast method that's why i am wondering if it will fail on mainnet.
Why this strange behavior with these two broadcast methods?
And Please confirm the above pasted transaction is multisig OR not?
Hi Nic,
Thanks For your support and sorry for throwing too much questions. Finally Its looking Resolved all the problems and I got success in implementing the multisig with QbitNinja.
In Last only need to confirm with you that below is the multisig transaction OR not? {{ "hash": "c3973f85cb332c031188af2292cb409a27c5fb9a31bbf8a4d0d421123661094d", "ver": 1, "vin_sz": 1, "vout_sz": 2, "lock_time": 0, "size": 478, "in": [ { "prev_out": { "hash": "4c3c832651ef78b40f9828f32114de32ffffe951210506d40df858dc61c70957", "n": 1 }, "scriptSig": "00207a1ced7a423c160de82476958aadc5e37e53c2bdea484c1ecb5ec0095241eccb", "witness": "0 304402202131cabe080936e71188c3ae4a9d74f3a0a5f1cf36386db46811b9f9ee7564bd02202e85a117a72ffc7afef29016a437fe8ae63326ec7d93c870e12077b7f01e303401 3045022100db3f21000a63fc3038e0e4408101b7eef0ecbfc98b0a168a2463e33c8190ccca02203e3707fcd401dee64e07b7532b6708fdd3f97bc232fa26c9fe21bd7d768d9f2701 3045022100844ea9c38588d506cb0a09b6d768b65567f86ef0ebf628619ea665ce9e6dc6ff02202e81c400a874362ec187a2d4c1e018743d86c85d2b6e8a95dd7558bfedac41a901 532103a49de10f94f503f51ba7785d5419d79d127726bb921bc646f4d1d579d2b0107221024699edf1996f54e698d53e6b57463eb96d9ea52522688a4dacdba4638835ac45210329c159fada835003a89bb06dcabb61fd8617ba09294568644a0c390756897a2b53ae" } ], "out": [ { "value": "0.69447109", "scriptPubKey": "OP_HASH160 dada67e42c94e7ada6df3bcffa7462f98c0aba80 OP_EQUAL" }, { "value": "0.00100000", "scriptPubKey": "OP_HASH160 6e907a596d5b95e91e2ffde01d72dee43410abb8 OP_EQUAL" } ] }}
it seems to be multi sig yes.
Thanks a lot for your reply :),One more thing Is it Sigwit enabled? As you suggested to use scriptPubKey.WitHash.ScriptPubKey.Hash.ScriptPubKey,and the same i applied,Really appreciating your support.
yes it is segwit enabled as I can see Witness data here.
Thanks you very much :),Now all my doubts clear except one broadcast problem,With testnet its broadcasting easily with _rpcClient.SendRawTransaction(objCustomTransactionHistory.Tranasction); and with mainnet its broadcasting easily with QbitNinja Broadcast method.
Hi Nic,How are you? I am little bit confused of how could i create a multisig transaction,I am using HD wallet,the process of transaction creation is given below:
private ApiResult BuildTransaction(int userID, int walletID, List rawTransaction, string destinationAddress, decimal amount, long totalBtc, FeeRate feeRate1, FeeRate feeRate2 = null)
{
Logger.Info("SENT BITCOIN TO ADDRESS: Starts Build Transaction");
In above code how could i build the transaction with P2SH (Pay To Script Hash) ,Please suggest, Thanks in Advance Abhinav Kumar