Skip to content

Commit b9be621

Browse files
author
willythecat
committed
Support for Bitcoin on the BitCash blockchain
1 parent 962bbb9 commit b9be621

35 files changed

+907
-148
lines changed

configure.ac

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
22
AC_PREREQ([2.60])
33
define(_CLIENT_VERSION_MAJOR, 0)
44
define(_CLIENT_VERSION_MINOR, 17)
5-
define(_CLIENT_VERSION_REVISION, 29)
5+
define(_CLIENT_VERSION_REVISION, 30)
66
define(_CLIENT_VERSION_BUILD, 0)
77
define(_CLIENT_VERSION_IS_RELEASE, true)
8-
define(_COPYRIGHT_YEAR, 2020)
8+
define(_COPYRIGHT_YEAR, 2021)
99
define(_COPYRIGHT_HOLDERS,[The %s developers])
1010
define(_COPYRIGHT_HOLDERS_SUBSTITUTION,[[Bitcash]])
1111
AC_INIT([Bitcash Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[https://github.com/WillyTheCat/BitCash/issues],[bitcash],[https://www.choosebitcash.com/])

src/chainparamsseeds.h

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
static SeedSpec6 pnSeed6_main[] = {
1212
{{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,192,227,166,148}, 5723},
13-
{{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,87,237,62,21}, 5723},
1413
{{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,94,23,33,130}, 5723},
1514
{{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,188,165,217,191}, 5723},
1615
{{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,188,165,192,204}, 5723},

src/consensus/tx_verify.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
135135
{
136136
if (tx.vin[i].isnickname)continue;
137137
const Coin& coin = inputs.AccessCoin(tx.vin[i].prevout);
138-
assert(!coin.IsSpent());
138+
if (!tx.isminttransaction())
139+
assert(!coin.IsSpent());
139140
const CTxOut &prevout = coin.out;
140141
if (prevout.scriptPubKey.IsPayToScriptHash())
141142
nSigOps += prevout.scriptPubKey.GetSigOpCount(tx.vin[i].scriptSig);
@@ -158,7 +159,8 @@ int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& i
158159
{
159160
if (tx.vin[i].isnickname)continue;
160161
const Coin& coin = inputs.AccessCoin(tx.vin[i].prevout);
161-
assert(!coin.IsSpent());
162+
if (!tx.isminttransaction())
163+
assert(!coin.IsSpent());
162164
const CTxOut &prevout = coin.out;
163165
nSigOps += CountWitnessSigOps(tx.vin[i].scriptSig, prevout.scriptPubKey, &tx.vin[i].scriptWitness, flags);
164166
}
@@ -193,9 +195,9 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe
193195

194196
for (const auto& txout : tx.vout)
195197
{
196-
if (txout.currency > 0 && tx.nVersion >= 9) return state.DoS(100, false, REJECT_INVALID, "Transactions which create Dollar or Gold are deactivated for now.");
198+
if ((txout.currency == 1 || txout.currency == 2) && tx.nVersion >= 9) return state.DoS(100, false, REJECT_INVALID, "Transactions which create Dollar or Gold are deactivated for now.");
197199

198-
if (txout.currency >= 3) return state.DoS(100, false, REJECT_INVALID, "bad-txns-vout-currency-not-supported");
200+
if (txout.currency >= 5) return state.DoS(100, false, REJECT_INVALID, "bad-txns-vout-currency-not-supported");
199201

200202
if (txout.referenceline.length()>1000)
201203
return state.DoS(100, false, REJECT_INVALID, "CTransaction::CheckTransaction() : txout.referenceline encrypted length>1000 characters");
@@ -286,6 +288,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe
286288

287289
bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, CAmount& txfee, uint256 blockhash, bool usehash, const CBlock* block)
288290
{
291+
if (tx.isminttransaction()) return true;
289292
CPubKey nicknamemasterpubkey(ParseHex(NicknameMasterPubKey));
290293
// are the actual inputs available?
291294
if (!inputs.HaveInputs(tx)) {
@@ -337,7 +340,6 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, c
337340

338341
continue;
339342
}
340-
341343
const COutPoint &prevout = tx.vin[i].prevout;
342344
const Coin& coin = inputs.AccessCoin(prevout);
343345
assert(!coin.IsSpent());
@@ -369,6 +371,15 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, c
369371
}
370372
}
371373

374+
for (const auto& txout : tx.vout)
375+
{
376+
if (currency > 2 || txout.currency > 2) {
377+
if (txout.currency != currency && (txout.currency != 4 || currency != 3)) {
378+
return state.DoS(100, false, REJECT_INVALID, "bad-txns-input-currency-must-match-output-currency");
379+
}
380+
}
381+
}
382+
372383

373384
CAmount value_out = tx.GetValueOut();
374385

src/interfaces/wallet.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx)
8383
result.debitusd = wtx.GetDebit(ISMINE_ALL,1);
8484
result.creditgold = wtx.GetCredit(ISMINE_ALL,2);
8585
result.debitgold = wtx.GetDebit(ISMINE_ALL,2);
86+
result.creditbitcoin = wtx.GetCredit(ISMINE_ALL,3);
87+
result.debitbitcoin = wtx.GetDebit(ISMINE_ALL,3);
8688
result.inputcurrency = wtx.GetInputCurrency();
8789
result.change = wtx.GetChange();
8890
result.time = wtx.GetTxTime();
@@ -407,6 +409,10 @@ class WalletImpl : public Wallet
407409
result.balanceGo = m_wallet.GetBalance(2);
408410
result.unconfirmed_balanceGo = m_wallet.GetUnconfirmedBalance(2);
409411
result.immature_balanceGo = m_wallet.GetImmatureBalance(2);
412+
result.balanceBi = m_wallet.GetBalance(3);
413+
result.unconfirmed_balanceBi = m_wallet.GetUnconfirmedBalance(3);
414+
result.immature_balanceBi = m_wallet.GetImmatureBalance(3);
415+
410416

411417
return result;
412418
}

src/interfaces/wallet.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ struct WalletBalances
353353
CAmount unconfirmed_balanceGo = 0;
354354
CAmount immature_balanceGo = 0;
355355

356+
CAmount balanceBi = 0;
357+
CAmount unconfirmed_balanceBi = 0;
358+
CAmount immature_balanceBi = 0;
359+
356360
bool balanceChanged(const WalletBalances& prev) const
357361
{
358362
return balance != prev.balance || unconfirmed_balance != prev.unconfirmed_balance ||
@@ -364,7 +368,10 @@ struct WalletBalances
364368
immature_balanceDo != prev.immature_balanceDo ||
365369

366370
balanceGo != prev.balanceGo || unconfirmed_balanceGo != prev.unconfirmed_balanceGo ||
367-
immature_balanceGo != prev.immature_balanceGo;
371+
immature_balanceGo != prev.immature_balanceGo ||
372+
373+
balanceBi != prev.balanceBi || unconfirmed_balanceBi != prev.unconfirmed_balanceBi ||
374+
immature_balanceBi != prev.immature_balanceBi;
368375

369376
}
370377
};
@@ -385,6 +392,8 @@ struct WalletTx
385392
CAmount debitusd;
386393
CAmount creditgold;
387394
CAmount debitgold;
395+
CAmount creditbitcoin;
396+
CAmount debitbitcoin;
388397
CAmount change;
389398
unsigned char inputcurrency;
390399
int64_t time;

src/key_io.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ std::string encodecurrency(const CTxDestination& dest,std::string str)
289289
{
290290
unsigned char currency = LocalGetCurrencyForDestination(dest);
291291
bool isdeposit = LocalGetDepositForDestination(dest);
292+
if (currency == 3) {
293+
return "bitcoin@"+str;
294+
} else
292295
if (currency == 2) {
293296
return "gold@"+str;
294297
} else
@@ -359,6 +362,10 @@ CTxDestination DecodeDestination(const std::string& strinput, const CChainParams
359362
bool isdeposit = false;
360363
std::string str = strinput;
361364

365+
if (str.length()>=7 && str[0]=='b' && str[1]=='i' && str[2]=='t' && str[3]=='c' && str[4]=='o' && str[5]=='i' && str[6]=='n' && str[7]=='@') {
366+
currency = 3;
367+
str.erase(0, 8);
368+
} else
362369
/* if (str.length()>=7 && str[0]=='g' && str[1]=='o' && str[2]=='l' && str[3]=='d' && str[4]=='@') {
363370
currency = 2;
364371
str.erase(0, 5);

src/miner.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ void BlockAssembler::CalculateFeesForBlock()
279279
CAmount pricerate = pblock->GetPriceinCurrency(0);
280280

281281
nFees = 0;
282+
int countmint = 0;
282283

283284
for (i = 1;i < pblock->vtx.size(); i++) {//start from transaction 1 not 0, because transaction 0 is the coinbase placeholder
284285

@@ -310,7 +311,10 @@ void BlockAssembler::CalculateFeesForBlock()
310311
txfee_aux = ((__int128_t)txfee_aux * (__int128_t)pblock->GetPriceinCurrency(2) / (__int128_t)COIN ) * (__int128_t)COIN / (__int128_t)pblock->GetPriceinCurrency(0);
311312
}
312313
}
313-
nFees += txfee_aux;
314+
if (!tx.isminttransaction())
315+
{
316+
nFees += txfee_aux;
317+
}
314318
}
315319
}
316320

@@ -1489,14 +1493,16 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
14891493
CAmount packageFees = iter->GetModFeesWithAncestors();
14901494
int64_t packageSigOpsCost = iter->GetSigOpCostWithAncestors();
14911495
bool isnick = iter->IsNicknameTx();
1496+
bool ismint = iter->IsMintTx();
14921497
if (fUsingModified) {
14931498
packageSize = modit->nSizeWithAncestors;
14941499
packageFees = modit->nModFeesWithAncestors;
14951500
packageSigOpsCost = modit->nSigOpCostWithAncestors;
14961501
isnick = modit->IsNicknameTx();
1502+
ismint = modit->IsMintTx();
14971503
}
14981504

1499-
if (!isnick && packageFees < blockMinFeeRate.GetFee(packageSize)) {
1505+
if (!ismint && !isnick && packageFees < blockMinFeeRate.GetFee(packageSize)) {
15001506
// Everything else we might consider has a lower fee rate
15011507
return;
15021508
}

src/miner.h

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct CTxMemPoolModifiedEntry {
7474
size_t GetTxSize() const { return iter->GetTxSize(); }
7575
const CTransaction& GetTx() const { return iter->GetTx(); }
7676
bool IsNicknameTx() const { return iter->IsNicknameTx(); }
77+
bool IsMintTx() const { return iter->IsMintTx(); }
7778

7879
CTxMemPool::txiter iter;
7980
uint64_t nSizeWithAncestors;

src/primitives/transaction.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ bool usemasterkeydummyonly;
2020
bool usepriceranges;
2121
bool usehashforcoinbase;
2222

23+
COutPoint CTxInMintCoins()
24+
{
25+
return COutPoint(uint256S("0x8ff824bc420ab27e8b47f02c058aa804236e701d09019851cbab1240b7bce292"), 0);
26+
}
27+
2328
std::string COutPoint::ToString() const
2429
{
2530
return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10), n);

src/primitives/transaction.h

+26
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class COutPoint
6262
std::string ToString() const;
6363
};
6464

65+
COutPoint CTxInMintCoins();
66+
6567
/** An input of a transaction. It contains the location of the previous
6668
* transaction's output that it claims and a signature that matches the
6769
* output's public key.
@@ -184,6 +186,11 @@ class CTxIn
184186
return !(a == b);
185187
}
186188

189+
bool isminttransaction() const
190+
{
191+
return prevout == COutPoint(uint256S("0x8ff824bc420ab27e8b47f02c058aa804236e701d09019851cbab1240b7bce292"), 0);
192+
}
193+
187194
std::string ToString() const;
188195
};
189196

@@ -545,6 +552,25 @@ class CTransaction
545552
}
546553
return false;
547554
}
555+
556+
bool isminttransaction() const
557+
{
558+
bool ismint = false;
559+
for (size_t i = 0; i < vin.size(); i++) {
560+
if (vin[i].isminttransaction()) {
561+
ismint = true;
562+
}
563+
}
564+
if (ismint)
565+
{
566+
for (size_t i = 0; i < vout.size(); i++) {
567+
if (vout[i].currency < 3) {
568+
return false;
569+
}
570+
}
571+
}
572+
return ismint;
573+
}
548574
};
549575

550576
/** A mutable version of CTransaction. */

0 commit comments

Comments
 (0)