mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
wallet|cj|tests: Adjust Dash-specific code to create signatures with Low R too
This commit is contained in:
parent
90154c6074
commit
e7d5f4087b
@ -135,19 +135,9 @@ CTransactionBuilder::CTransactionBuilder(std::shared_ptr<CWallet> pwalletIn, con
|
||||
CPubKey dummyPubkey = pwallet->GenerateNewKey(dummyBatch, 0, false);
|
||||
dummyBatch.TxnAbort();
|
||||
dummyScript = ::GetScriptForDestination(dummyPubkey.GetID());
|
||||
// Create dummy signatures for all inputs
|
||||
int nIn = 0;
|
||||
for (const auto& coin : tallyItem.vecInputCoins) {
|
||||
const CScript& scriptPubKey = coin.txout.scriptPubKey;
|
||||
SignatureData sigdata;
|
||||
bool res = ProduceSignature(*pwallet, DUMMY_SIGNATURE_CREATOR, scriptPubKey, sigdata);
|
||||
assert(res);
|
||||
UpdateInput(dummyTx.vin[nIn], sigdata);
|
||||
nIn++;
|
||||
}
|
||||
// Calculate required bytes for the dummy signed tx with tallyItem's inputs only
|
||||
nBytesBase = CalculateMaximumSignedTxSize(dummyTx, pwallet.get(), false);
|
||||
}
|
||||
// Calculate required bytes for the dummy tx with tallyItem's inputs only
|
||||
nBytesBase = ::GetSerializeSize(dummyTx, SER_NETWORK, PROTOCOL_VERSION);
|
||||
// Calculate the output size
|
||||
nBytesOutput = ::GetSerializeSize(CTxOut(0, dummyScript), SER_NETWORK, PROTOCOL_VERSION);
|
||||
// Just to make sure..
|
||||
|
@ -107,20 +107,20 @@ public:
|
||||
BOOST_FIXTURE_TEST_CASE(CTransactionBuilderTest, CTransactionBuilderTestSetup)
|
||||
{
|
||||
// NOTE: Mock wallet version is FEATURE_BASE which means that it uses uncompressed pubkeys
|
||||
// (65 bytes instead of 33 bytes), so CTxIn size is 180 bytes, not 148 bytes as one might expect.
|
||||
// (65 bytes instead of 33 bytes), so CTxIn size is 179 bytes, not 147 bytes as one might expect.
|
||||
// Each output is 34 bytes, vin and vout compact sizes are 1 byte each.
|
||||
// Therefore base size (i.e. for a tx with 1 input, 0 outputs) is expected to be
|
||||
// 4(n32bitVersion) + 1(vin size) + 180(vin[0]) + 1(vout size) + 4(nLockTime) = 190 bytes.
|
||||
// 4(n32bitVersion) + 1(vin size) + 179(vin[0]) + 1(vout size) + 4(nLockTime) = 189 bytes.
|
||||
|
||||
minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE);
|
||||
// Tests with single outpoint tallyItem
|
||||
{
|
||||
CompactTallyItem tallyItem = GetTallyItem({5000});
|
||||
CompactTallyItem tallyItem = GetTallyItem({4999});
|
||||
CTransactionBuilder txBuilder(wallet, tallyItem);
|
||||
|
||||
BOOST_CHECK_EQUAL(txBuilder.CountOutputs(), 0);
|
||||
BOOST_CHECK_EQUAL(txBuilder.GetAmountInitial(), tallyItem.nAmount);
|
||||
BOOST_CHECK_EQUAL(txBuilder.GetAmountLeft(), 4810); // 5000 - 190
|
||||
BOOST_CHECK_EQUAL(txBuilder.GetAmountLeft(), 4810); // 4999 - 189
|
||||
|
||||
BOOST_CHECK(txBuilder.CouldAddOutput(4776)); // 4810 - 34
|
||||
BOOST_CHECK(!txBuilder.CouldAddOutput(4777));
|
||||
@ -131,7 +131,7 @@ BOOST_FIXTURE_TEST_CASE(CTransactionBuilderTest, CTransactionBuilderTestSetup)
|
||||
BOOST_CHECK(txBuilder.CouldAddOutputs({1000, 1000, 2708})); // (4810 - 34 * 3) split in 3 outputs
|
||||
BOOST_CHECK(!txBuilder.CouldAddOutputs({1000, 1000, 2709}));
|
||||
|
||||
BOOST_CHECK_EQUAL(txBuilder.AddOutput(5000), nullptr);
|
||||
BOOST_CHECK_EQUAL(txBuilder.AddOutput(4999), nullptr);
|
||||
BOOST_CHECK_EQUAL(txBuilder.AddOutput(-1), nullptr);
|
||||
|
||||
CTransactionBuilderOutput* output = txBuilder.AddOutput();
|
||||
|
@ -3719,23 +3719,12 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
|
||||
}
|
||||
|
||||
auto calculateFee = [&](CAmount& nFee) -> bool {
|
||||
// Fill in dummy signatures for fee calculation.
|
||||
int nIn = 0;
|
||||
for (const auto& coin : vecCoins) {
|
||||
const CScript& scriptPubKey = coin.txout.scriptPubKey;
|
||||
SignatureData sigdata;
|
||||
if (!ProduceSignature(*this, DUMMY_SIGNATURE_CREATOR, scriptPubKey, sigdata)) {
|
||||
strFailReason = _("Signing transaction failed");
|
||||
return false;
|
||||
} else {
|
||||
UpdateInput(txNew.vin[nIn], sigdata);
|
||||
}
|
||||
|
||||
nIn++;
|
||||
nBytes = CalculateMaximumSignedTxSize(txNew, this, coin_control.fAllowWatchOnly);
|
||||
if (nBytes < 0) {
|
||||
strFailReason = _("Signing transaction failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION);
|
||||
|
||||
if (nExtraPayloadSize != 0) {
|
||||
// account for extra payload in fee calculation
|
||||
nBytes += GetSizeOfCompactSize(nExtraPayloadSize) + nExtraPayloadSize;
|
||||
|
Loading…
Reference in New Issue
Block a user