Merge branch 'danger' into dev

This commit is contained in:
Duke Leto
2022-07-12 08:32:48 -04:00
21 changed files with 232 additions and 82 deletions

View File

@@ -41,7 +41,6 @@ zcash_gtest_SOURCES += \
gtest/test_txid.cpp \ gtest/test_txid.cpp \
gtest/test_libzcash_utils.cpp \ gtest/test_libzcash_utils.cpp \
gtest/test_proofs.cpp \ gtest/test_proofs.cpp \
gtest/test_paymentdisclosure.cpp \
gtest/test_pedersen_hash.cpp \ gtest/test_pedersen_hash.cpp \
gtest/test_checkblock.cpp \ gtest/test_checkblock.cpp \
gtest/test_zip32.cpp gtest/test_zip32.cpp

View File

@@ -12,8 +12,8 @@ hush_test_SOURCES = test-hush/main.cpp
# test-hush/test_cryptoconditions.cpp \ # test-hush/test_cryptoconditions.cpp \
# test-hush/test_coinimport.cpp \ # test-hush/test_coinimport.cpp \
# test-hush/test_eval_bet.cpp \ # test-hush/test_eval_bet.cpp \
# test-hush/test_eval_notarisation.cpp \ # test-hush/test_eval_notarization.cpp \
# test-hush/test_parse_notarisation.cpp \ # test-hush/test_parse_notarization.cpp \
# test-hush/test_addrman.cpp \ # test-hush/test_addrman.cpp \
# test-hush/test_netbase_tests.cpp # test-hush/test_netbase_tests.cpp

View File

@@ -496,13 +496,13 @@ channelsopen:
Used to open channel between two pub keys (sender and receiver). Parameters: destination_pubkey, total_number_of_payments, payment_denomination. Used to open channel between two pub keys (sender and receiver). Parameters: destination_pubkey, total_number_of_payments, payment_denomination.
Example - channelsopen 03a8fe537de2ace0d9c210b0ff945085c9192c9abf56ea22f22ce7998f289bb7bb 10 10000000 Example - channelsopen 03a8fe537de2ace0d9c210b0ff945085c9192c9abf56ea22f22ce7998f289bb7bb 10 10000000
channelspayment: channelspayment:
Sending payment to receiver. Condition is that the channel open tx is confirmed/notarised. Parameters: open_tx_id, payment_amount, [secret] (optional, used when receiver needs to make a payment which secret has already been revealed by sender). Sending payment to receiver. Condition is that the channel open tx is confirmed/notarized. Parameters: open_tx_id, payment_amount, [secret] (optional, used when receiver needs to make a payment which secret has already been revealed by sender).
Example - channelspayment b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440 20000000 Example - channelspayment b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440 20000000
channelsclose: channelsclose:
Marking channel as closed. This RPC only creates a tx which says that the channel is closed and will be used in refund RPC to withdraw funds from closed channel. This also notifies receiver that channel fund could be withdrawn, but the payment RPC is still available until all funds are withdrawn. Parameters: open_tx_id. Marking channel as closed. This RPC only creates a tx which says that the channel is closed and will be used in refund RPC to withdraw funds from closed channel. This also notifies receiver that channel fund could be withdrawn, but the payment RPC is still available until all funds are withdrawn. Parameters: open_tx_id.
Example - channelsclose b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440 Example - channelsclose b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440
channelsrefund: channelsrefund:
Withdrawing funds back to senders address. Refund can be issued only when channel close tx is confirmed/notarised. Parameters: open_tx_id, close_tx_id Withdrawing funds back to senders address. Refund can be issued only when channel close tx is confirmed/notarized. Parameters: open_tx_id, close_tx_id
Example - channelsrefund b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440 bb0ea34f846247642684c7c541c435b06ee79e47893640e5d2e51023841677fd Example - channelsrefund b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440 bb0ea34f846247642684c7c541c435b06ee79e47893640e5d2e51023841677fd
channelsinfo: channelsinfo:
Getting info about channels in which the issuer is involved, either as sender or receiver. Call without parameters give the list of available channels. Parameters: [open_tx_id] (optional - used to get info about specific channel) Getting info about channels in which the issuer is involved, either as sender or receiver. Call without parameters give the list of available channels. Parameters: [open_tx_id] (optional - used to get info about specific channel)

View File

@@ -164,7 +164,7 @@ bool GetOpReturnHash(CScript script, uint256 &hash)
/* /*
* Crypto-Condition EVAL method that verifies a payout against a transaction * Crypto-Condition EVAL method that verifies a payout against a transaction
* notarised on another chain. * notarized on another chain.
* *
* IN: params - condition params * IN: params - condition params
* IN: importTx - Payout transaction on value chain (HUSH) * IN: importTx - Payout transaction on value chain (HUSH)
@@ -219,7 +219,7 @@ bool Eval::ImportPayout(const std::vector<uint8_t> params, const CTransaction &i
// Check disputeTx solves momproof from vout[0] // Check disputeTx solves momproof from vout[0]
{ {
NotarizationData data(0); NotarizationData data(0);
if (!GetNotarizationData(proof.notarisationHash, data)) if (!GetNotarizationData(proof.notarizationHash, data))
return Invalid("coudnt-load-mom"); return Invalid("coudnt-load-mom");
if (data.MoM != proof.branch.Exec(disputeTx.GetHash())) if (data.MoM != proof.branch.Exec(disputeTx.GetHash()))

View File

@@ -29,12 +29,12 @@ class MoMProof
{ {
public: public:
MerkleBranch branch; MerkleBranch branch;
uint256 notarisationHash; uint256 notarizationHash;
ADD_SERIALIZE_METHODS; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) { inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(branch); READWRITE(branch);
READWRITE(notarisationHash); READWRITE(notarizationHash);
} }
}; };

View File

@@ -250,7 +250,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &
else if ( ConstrainVout(channelOpenTx.vout[2],1,destmarker,CC_MARKER_VALUE)==0 ) else if ( ConstrainVout(channelOpenTx.vout[2],1,destmarker,CC_MARKER_VALUE)==0 )
return eval->Invalid("vout.2 is CC marker to destpub or invalid amount for channelopen!"); return eval->Invalid("vout.2 is CC marker to destpub or invalid amount for channelopen!");
else if (hush_txnotarizedconfirmed(opentxid) == 0) else if (hush_txnotarizedconfirmed(opentxid) == 0)
return eval->Invalid("channelopen is not yet confirmed(notarised)!"); return eval->Invalid("channelopen is not yet confirmed(notarized)!");
else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) else if ( IsCCInput(tx.vin[0].scriptSig) != 0 )
return eval->Invalid("vin.0 is normal for channelpayment!"); return eval->Invalid("vin.0 is normal for channelpayment!");
else if ( IsCCInput(tx.vin[tx.vin.size()-2].scriptSig) == 0 ) else if ( IsCCInput(tx.vin[tx.vin.size()-2].scriptSig) == 0 )
@@ -311,7 +311,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &
else if ( ConstrainVout(channelOpenTx.vout[2],1,destmarker,CC_MARKER_VALUE)==0 ) else if ( ConstrainVout(channelOpenTx.vout[2],1,destmarker,CC_MARKER_VALUE)==0 )
return eval->Invalid("vout.2 is CC marker to destpub or invalid amount for channelopen!"); return eval->Invalid("vout.2 is CC marker to destpub or invalid amount for channelopen!");
else if (hush_txnotarizedconfirmed(opentxid) == 0) else if (hush_txnotarizedconfirmed(opentxid) == 0)
return eval->Invalid("channelopen is not yet confirmed(notarised)!"); return eval->Invalid("channelopen is not yet confirmed(notarized)!");
else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) else if ( IsCCInput(tx.vin[0].scriptSig) != 0 )
return eval->Invalid("vin.0 is normal for channelclose!"); return eval->Invalid("vin.0 is normal for channelclose!");
else if ( IsCCInput(tx.vin[tx.vin.size()-2].scriptSig) == 0 ) else if ( IsCCInput(tx.vin[tx.vin.size()-2].scriptSig) == 0 )
@@ -352,9 +352,9 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &
else if ( ConstrainVout(channelOpenTx.vout[2],1,destmarker,CC_MARKER_VALUE)==0 ) else if ( ConstrainVout(channelOpenTx.vout[2],1,destmarker,CC_MARKER_VALUE)==0 )
return eval->Invalid("vout.2 is CC marker to destpub or invalid amount for channelopen!"); return eval->Invalid("vout.2 is CC marker to destpub or invalid amount for channelopen!");
else if (hush_txnotarizedconfirmed(opentxid) == 0) else if (hush_txnotarizedconfirmed(opentxid) == 0)
return eval->Invalid("channelopen is not yet confirmed(notarised)!"); return eval->Invalid("channelopen is not yet confirmed(notarized)!");
else if (hush_txnotarizedconfirmed(param3) == 0) else if (hush_txnotarizedconfirmed(param3) == 0)
return eval->Invalid("channelClose is not yet confirmed(notarised)!"); return eval->Invalid("channelClose is not yet confirmed(notarized)!");
else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) else if ( IsCCInput(tx.vin[0].scriptSig) != 0 )
return eval->Invalid("vin.0 is normal for channelrefund!"); return eval->Invalid("vin.0 is normal for channelrefund!");
else if ( IsCCInput(tx.vin[tx.vin.size()-2].scriptSig) == 0 ) else if ( IsCCInput(tx.vin[tx.vin.size()-2].scriptSig) == 0 )

View File

@@ -180,14 +180,14 @@ bool Eval::CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t t
return CheckTxAuthority(tx, auth); return CheckTxAuthority(tx, auth);
} }
// Get MoM from a notarisation tx hash (on HUSH) // Get MoM from a notarization tx hash (on HUSH)
bool Eval::GetNotarizationData(const uint256 notaryHash, NotarizationData &data) const bool Eval::GetNotarizationData(const uint256 notaryHash, NotarizationData &data) const
{ {
CTransaction notarisationTx; CTransaction notarizationTx;
CBlockIndex block; CBlockIndex block;
if (!GetTxConfirmed(notaryHash, notarisationTx, block)) return false; if (!GetTxConfirmed(notaryHash, notarizationTx, block)) return false;
if (!CheckNotaryInputs(notarisationTx, block.GetHeight(), block.nTime)) return false; if (!CheckNotaryInputs(notarizationTx, block.GetHeight(), block.nTime)) return false;
if (!ParseNotarizationOpReturn(notarisationTx, data)) return false; if (!ParseNotarizationOpReturn(notarizationTx, data)) return false;
return true; return true;
} }
@@ -205,7 +205,7 @@ std::string Eval::GetAssetchainsSymbol() const
/* /*
* Notarization data, ie, OP_RETURN payload in notarisation transactions * Notarization data, ie, OP_RETURN payload in notarization transactions
*/ */
bool ParseNotarizationOpReturn(const CTransaction &tx, NotarizationData &data) bool ParseNotarizationOpReturn(const CTransaction &tx, NotarizationData &data)
{ {

View File

@@ -110,7 +110,7 @@ public:
virtual bool GetSpendsConfirmed(uint256 hash, std::vector<CTransaction> &spends) const; virtual bool GetSpendsConfirmed(uint256 hash, std::vector<CTransaction> &spends) const;
virtual bool GetBlock(uint256 hash, CBlockIndex& blockIdx) const; virtual bool GetBlock(uint256 hash, CBlockIndex& blockIdx) const;
virtual int32_t GetNotaries(uint8_t pubkeys[64][33], int32_t height, uint32_t timestamp) const; virtual int32_t GetNotaries(uint8_t pubkeys[64][33], int32_t height, uint32_t timestamp) const;
virtual bool GetNotarizationData(uint256 notarisationHash, NotarizationData &data) const; virtual bool GetNotarizationData(uint256 notarizationHash, NotarizationData &data) const;
virtual bool CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const; virtual bool CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const;
virtual uint32_t GetAssetchainsCC() const; virtual uint32_t GetAssetchainsCC() const;
virtual std::string GetAssetchainsSymbol() const; virtual std::string GetAssetchainsSymbol() const;
@@ -158,7 +158,7 @@ extern char SMART_CHAIN_SYMBOL[65];
/* /*
* Data from notarisation OP_RETURN from chain being notarised * Data from notarization OP_RETURN from chain being notarized
*/ */
class NotarizationData class NotarizationData
{ {

View File

@@ -613,7 +613,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
return eval->Invalid(validationError); return eval->Invalid(validationError);
} }
else if (hush_txnotarizedconfirmed(bindtxid) == false) else if (hush_txnotarizedconfirmed(bindtxid) == false)
return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!");
else if (myGetTransaction(deposittxid,tmptx,hashblock) == 0) else if (myGetTransaction(deposittxid,tmptx,hashblock) == 0)
return eval->Invalid("invalid gatewaysdeposittxid!"); return eval->Invalid("invalid gatewaysdeposittxid!");
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysDepositOpRet(tmptx.vout[numvouts-1].scriptPubKey,tmptxid,tmprefcoin,tmppublishers,txids,height,cointxid,claimvout,hex,proof,tmppubkey,tmpamount) != 'D') else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysDepositOpRet(tmptx.vout[numvouts-1].scriptPubKey,tmptxid,tmprefcoin,tmppublishers,txids,height,cointxid,claimvout,hex,proof,tmppubkey,tmpamount) != 'D')
@@ -631,7 +631,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
else if (tmpamount>totalsupply) else if (tmpamount>totalsupply)
return eval->Invalid("deposit amount greater then bind total supply"); return eval->Invalid("deposit amount greater then bind total supply");
else if (hush_txnotarizedconfirmed(deposittxid) == false) else if (hush_txnotarizedconfirmed(deposittxid) == false)
return eval->Invalid("gatewaysdeposit tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewaysdeposit tx is not yet confirmed(notarized)!");
else if (tx.vin.size()>0) else if (tx.vin.size()>0)
{ {
i=0; i=0;
@@ -705,7 +705,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
else if ( ConstrainVout(tmptx.vout[1],1,gatewaystokensaddr,amount)==0) else if ( ConstrainVout(tmptx.vout[1],1,gatewaystokensaddr,amount)==0)
return eval->Invalid("invalid tokens to gateways vout for gatewaysWithdraw!"); return eval->Invalid("invalid tokens to gateways vout for gatewaysWithdraw!");
else if (hush_txnotarizedconfirmed(withdrawtxid) == false) else if (hush_txnotarizedconfirmed(withdrawtxid) == false)
return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarized)!");
else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0)
return eval->Invalid("invalid gatewaysbind txid!"); return eval->Invalid("invalid gatewaysbind txid!");
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B')
@@ -715,7 +715,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
else if (tmptokenid!=tokenid) else if (tmptokenid!=tokenid)
return eval->Invalid("tokenid does not match tokenid from gatewaysbind"); return eval->Invalid("tokenid does not match tokenid from gatewaysbind");
else if (hush_txnotarizedconfirmed(bindtxid) == false) else if (hush_txnotarizedconfirmed(bindtxid) == false)
return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!");
else if (IsCCInput(tx.vin[0].scriptSig) != 0) else if (IsCCInput(tx.vin[0].scriptSig) != 0)
return eval->Invalid("vin.0 is normal for gatewayspartialsign!"); return eval->Invalid("vin.0 is normal for gatewayspartialsign!");
else if ((*cp->ismyvin)(tx.vin[tx.vin.size()-1].scriptSig) == 0 || myGetTransaction(tx.vin[tx.vin.size()-1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[tx.vin.size()-1].prevout.n].nValue!=CC_MARKER_VALUE) else if ((*cp->ismyvin)(tx.vin[tx.vin.size()-1].scriptSig) == 0 || myGetTransaction(tx.vin[tx.vin.size()-1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[tx.vin.size()-1].prevout.n].nValue!=CC_MARKER_VALUE)
@@ -747,7 +747,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
else if (tmptx.vout[1].nValue!=amount) else if (tmptx.vout[1].nValue!=amount)
return eval->Invalid("amount in opret not matching tx tokens amount!"); return eval->Invalid("amount in opret not matching tx tokens amount!");
else if (hush_txnotarizedconfirmed(withdrawtxid) == false) else if (hush_txnotarizedconfirmed(withdrawtxid) == false)
return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarized)!");
else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0)
return eval->Invalid("invalid gatewaysbind txid!"); return eval->Invalid("invalid gatewaysbind txid!");
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B')
@@ -757,7 +757,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
else if (tmptokenid!=tokenid) else if (tmptokenid!=tokenid)
return eval->Invalid("tokenid does not match tokenid from gatewaysbind"); return eval->Invalid("tokenid does not match tokenid from gatewaysbind");
else if (hush_txnotarizedconfirmed(bindtxid) == false) else if (hush_txnotarizedconfirmed(bindtxid) == false)
return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!");
else if (IsCCInput(tx.vin[0].scriptSig) != 0) else if (IsCCInput(tx.vin[0].scriptSig) != 0)
return eval->Invalid("vin.0 is normal for gatewayscompletesigning!"); return eval->Invalid("vin.0 is normal for gatewayscompletesigning!");
else if ((*cp->ismyvin)(tx.vin[tx.vin.size()-1].scriptSig) == 0 || myGetTransaction(tx.vin[tx.vin.size()-1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[tx.vin.size()-1].prevout.n].nValue!=CC_MARKER_VALUE) else if ((*cp->ismyvin)(tx.vin[tx.vin.size()-1].scriptSig) == 0 || myGetTransaction(tx.vin[tx.vin.size()-1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[tx.vin.size()-1].prevout.n].nValue!=CC_MARKER_VALUE)
@@ -778,7 +778,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
else if ((numvouts=tmptx.vout.size()) > 0 && DecodeGatewaysCompleteSigningOpRet(tmptx.vout[numvouts-1].scriptPubKey,withdrawtxid,tmprefcoin,K,hex)!='S') else if ((numvouts=tmptx.vout.size()) > 0 && DecodeGatewaysCompleteSigningOpRet(tmptx.vout[numvouts-1].scriptPubKey,withdrawtxid,tmprefcoin,K,hex)!='S')
return eval->Invalid("invalid gatewayscompletesigning OP_RETURN data!"); return eval->Invalid("invalid gatewayscompletesigning OP_RETURN data!");
else if (hush_txnotarizedconfirmed(completetxid) == false) else if (hush_txnotarizedconfirmed(completetxid) == false)
return eval->Invalid("gatewayscompletesigning tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewayscompletesigning tx is not yet confirmed(notarized)!");
else if (myGetTransaction(withdrawtxid,tmptx,hashblock) == 0) else if (myGetTransaction(withdrawtxid,tmptx,hashblock) == 0)
return eval->Invalid("invalid withdraw txid!"); return eval->Invalid("invalid withdraw txid!");
else if ((numvouts=tmptx.vout.size()) > 0 && DecodeGatewaysWithdrawOpRet(tmptx.vout[numvouts-1].scriptPubKey,tmptokenid,bindtxid,tmprefcoin,pubkey,amount)!='W') else if ((numvouts=tmptx.vout.size()) > 0 && DecodeGatewaysWithdrawOpRet(tmptx.vout[numvouts-1].scriptPubKey,tmptokenid,bindtxid,tmprefcoin,pubkey,amount)!='W')
@@ -786,7 +786,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
else if (tmprefcoin!=refcoin) else if (tmprefcoin!=refcoin)
return eval->Invalid("refcoin different than in bind tx"); return eval->Invalid("refcoin different than in bind tx");
else if (hush_txnotarizedconfirmed(withdrawtxid) == false) else if (hush_txnotarizedconfirmed(withdrawtxid) == false)
return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarized)!");
else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0)
return eval->Invalid("invalid gatewaysbind txid!"); return eval->Invalid("invalid gatewaysbind txid!");
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B')
@@ -796,7 +796,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
else if (tmptokenid!=tokenid) else if (tmptokenid!=tokenid)
return eval->Invalid("tokenid does not match tokenid from gatewaysbind"); return eval->Invalid("tokenid does not match tokenid from gatewaysbind");
else if (hush_txnotarizedconfirmed(bindtxid) == false) else if (hush_txnotarizedconfirmed(bindtxid) == false)
return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!");
else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) else if ( IsCCInput(tx.vin[0].scriptSig) != 0 )
return eval->Invalid("vin.0 is normal for gatewaysmarkdone!"); return eval->Invalid("vin.0 is normal for gatewaysmarkdone!");
else if ((*cp->ismyvin)(tx.vin[tx.vin.size()-1].scriptSig) == 0 || myGetTransaction(tx.vin[tx.vin.size()-1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[tx.vin.size()-1].prevout.n].nValue!=CC_MARKER_VALUE) else if ((*cp->ismyvin)(tx.vin[tx.vin.size()-1].scriptSig) == 0 || myGetTransaction(tx.vin[tx.vin.size()-1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[tx.vin.size()-1].prevout.n].nValue!=CC_MARKER_VALUE)

View File

@@ -361,7 +361,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact
else if (tmptx.vout[1].nValue!=amount) else if (tmptx.vout[1].nValue!=amount)
return eval->Invalid("amount in opret not matching tx tokens amount!"); return eval->Invalid("amount in opret not matching tx tokens amount!");
else if (hush_txnotarizedconfirmed(withdrawtxid) == false) else if (hush_txnotarizedconfirmed(withdrawtxid) == false)
return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarized)!");
else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0)
return eval->Invalid("invalid gatewaysbind txid!"); return eval->Invalid("invalid gatewaysbind txid!");
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeImportGatewayBindOpRet(burnaddr,tmptx.vout[numvouts-1].scriptPubKey,tmprefcoin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') else if ((numvouts=tmptx.vout.size()) < 1 || DecodeImportGatewayBindOpRet(burnaddr,tmptx.vout[numvouts-1].scriptPubKey,tmprefcoin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B')
@@ -369,7 +369,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact
else if (tmprefcoin!=refcoin) else if (tmprefcoin!=refcoin)
return eval->Invalid("refcoin different than in bind tx"); return eval->Invalid("refcoin different than in bind tx");
else if (hush_txnotarizedconfirmed(bindtxid) == false) else if (hush_txnotarizedconfirmed(bindtxid) == false)
return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!");
else if (IsCCInput(tx.vin[0].scriptSig) != 0) else if (IsCCInput(tx.vin[0].scriptSig) != 0)
return eval->Invalid("vin.0 is normal for gatewayspartialsign!"); return eval->Invalid("vin.0 is normal for gatewayspartialsign!");
else if ((*cp->ismyvin)(tx.vin[1].scriptSig) == 0 || myGetTransaction(tx.vin[1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[1].prevout.n].nValue!=CC_MARKER_VALUE) else if ((*cp->ismyvin)(tx.vin[1].scriptSig) == 0 || myGetTransaction(tx.vin[1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[1].prevout.n].nValue!=CC_MARKER_VALUE)
@@ -403,7 +403,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact
else if (tmptx.vout[1].nValue!=amount) else if (tmptx.vout[1].nValue!=amount)
return eval->Invalid("amount in opret not matching tx tokens amount!"); return eval->Invalid("amount in opret not matching tx tokens amount!");
else if (hush_txnotarizedconfirmed(withdrawtxid) == false) else if (hush_txnotarizedconfirmed(withdrawtxid) == false)
return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarized)!");
else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0)
return eval->Invalid("invalid gatewaysbind txid!"); return eval->Invalid("invalid gatewaysbind txid!");
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeImportGatewayBindOpRet(burnaddr,tmptx.vout[numvouts-1].scriptPubKey,tmprefcoin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') else if ((numvouts=tmptx.vout.size()) < 1 || DecodeImportGatewayBindOpRet(burnaddr,tmptx.vout[numvouts-1].scriptPubKey,tmprefcoin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B')
@@ -411,7 +411,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact
else if (tmprefcoin!=refcoin) else if (tmprefcoin!=refcoin)
return eval->Invalid("refcoin different than in bind tx"); return eval->Invalid("refcoin different than in bind tx");
else if (hush_txnotarizedconfirmed(bindtxid) == false) else if (hush_txnotarizedconfirmed(bindtxid) == false)
return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!");
else if (IsCCInput(tx.vin[0].scriptSig) != 0) else if (IsCCInput(tx.vin[0].scriptSig) != 0)
return eval->Invalid("vin.0 is normal for gatewayscompletesigning!"); return eval->Invalid("vin.0 is normal for gatewayscompletesigning!");
else if ((*cp->ismyvin)(tx.vin[1].scriptSig) == 0 || myGetTransaction(tx.vin[1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[1].prevout.n].nValue!=CC_MARKER_VALUE) else if ((*cp->ismyvin)(tx.vin[1].scriptSig) == 0 || myGetTransaction(tx.vin[1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[1].prevout.n].nValue!=CC_MARKER_VALUE)
@@ -432,7 +432,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact
else if ((numvouts=tmptx.vout.size()) > 0 && DecodeImportGatewayCompleteSigningOpRet(tmptx.vout[numvouts-1].scriptPubKey,withdrawtxid,tmprefcoin,K,hex)!='S') else if ((numvouts=tmptx.vout.size()) > 0 && DecodeImportGatewayCompleteSigningOpRet(tmptx.vout[numvouts-1].scriptPubKey,withdrawtxid,tmprefcoin,K,hex)!='S')
return eval->Invalid("invalid gatewayscompletesigning OP_RETURN data!"); return eval->Invalid("invalid gatewayscompletesigning OP_RETURN data!");
else if (hush_txnotarizedconfirmed(completetxid) == false) else if (hush_txnotarizedconfirmed(completetxid) == false)
return eval->Invalid("gatewayscompletesigning tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewayscompletesigning tx is not yet confirmed(notarized)!");
else if (myGetTransaction(withdrawtxid,tmptx,hashblock) == 0) else if (myGetTransaction(withdrawtxid,tmptx,hashblock) == 0)
return eval->Invalid("invalid withdraw txid!"); return eval->Invalid("invalid withdraw txid!");
else if ((numvouts=tmptx.vout.size()) > 0 && DecodeImportGatewayWithdrawOpRet(tmptx.vout[numvouts-1].scriptPubKey,bindtxid,tmprefcoin,pubkey,amount)!='W') else if ((numvouts=tmptx.vout.size()) > 0 && DecodeImportGatewayWithdrawOpRet(tmptx.vout[numvouts-1].scriptPubKey,bindtxid,tmprefcoin,pubkey,amount)!='W')
@@ -440,7 +440,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact
else if (tmprefcoin!=refcoin) else if (tmprefcoin!=refcoin)
return eval->Invalid("refcoin different than in bind tx"); return eval->Invalid("refcoin different than in bind tx");
else if (hush_txnotarizedconfirmed(withdrawtxid) == false) else if (hush_txnotarizedconfirmed(withdrawtxid) == false)
return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarized)!");
else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0)
return eval->Invalid("invalid gatewaysbind txid!"); return eval->Invalid("invalid gatewaysbind txid!");
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeImportGatewayBindOpRet(burnaddr,tmptx.vout[numvouts-1].scriptPubKey,tmprefcoin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') else if ((numvouts=tmptx.vout.size()) < 1 || DecodeImportGatewayBindOpRet(burnaddr,tmptx.vout[numvouts-1].scriptPubKey,tmprefcoin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B')
@@ -448,7 +448,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact
else if (tmprefcoin!=refcoin) else if (tmprefcoin!=refcoin)
return eval->Invalid("refcoin different than in bind tx"); return eval->Invalid("refcoin different than in bind tx");
else if (hush_txnotarizedconfirmed(bindtxid) == false) else if (hush_txnotarizedconfirmed(bindtxid) == false)
return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!");
else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) else if ( IsCCInput(tx.vin[0].scriptSig) != 0 )
return eval->Invalid("vin.0 is normal for gatewaysmarkdone!"); return eval->Invalid("vin.0 is normal for gatewaysmarkdone!");
else if ((*cp->ismyvin)(tx.vin[1].scriptSig) == 0 || myGetTransaction(tx.vin[1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[1].prevout.n].nValue!=CC_MARKER_VALUE) else if ((*cp->ismyvin)(tx.vin[1].scriptSig) == 0 || myGetTransaction(tx.vin[1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[1].prevout.n].nValue!=CC_MARKER_VALUE)

View File

@@ -28,7 +28,7 @@
/* /*
* Crypto-Condition EVAL method that verifies a payout against a transaction * Crypto-Condition EVAL method that verifies a payout against a transaction
* notarised on another chain. * notarized on another chain.
* *
* IN: params - condition params * IN: params - condition params
* IN: importTx - Payout transaction on value chain (HUSH) * IN: importTx - Payout transaction on value chain (HUSH)
@@ -83,7 +83,7 @@ bool Eval::ImportPayout(const std::vector<uint8_t> params, const CTransaction &i
// Check disputeTx solves momproof from vout[0] // Check disputeTx solves momproof from vout[0]
{ {
NotarizationData data; NotarizationData data;
if (!GetNotarizationData(proof.notarisationHash, data)) if (!GetNotarizationData(proof.notarizationHash, data))
return Invalid("coudnt-load-mom"); return Invalid("coudnt-load-mom");
if (data.MoM != proof.Exec(disputeTx.GetHash())) if (data.MoM != proof.Exec(disputeTx.GetHash()))

View File

@@ -578,13 +578,13 @@ bool CCoinsViewCache::HaveShieldedRequirements(const CTransaction& tx) const
{ {
for (const SpendDescription &spendDescription : tx.vShieldedSpend) { for (const SpendDescription &spendDescription : tx.vShieldedSpend) {
if (GetNullifier(spendDescription.nullifier, SAPLING)) { // Prevent double spends if (GetNullifier(spendDescription.nullifier, SAPLING)) { // Prevent double spends
LogPrintf("%s: sapling nullifier %s exists, preventing double spend\n", __FUNCTION__, spendDescription.nullifier.GetHex().c_str()); LogPrintf("%s: sapling nullifier %s exists, preventing double spend in tx %s\n", __FUNCTION__, spendDescription.nullifier.GetHex().c_str(), tx.GetHash().GetHex().c_str());
return false; return false;
} }
SaplingMerkleTree tree; SaplingMerkleTree tree;
if (!GetSaplingAnchorAt(spendDescription.anchor, tree)) { if (!GetSaplingAnchorAt(spendDescription.anchor, tree)) {
LogPrintf("%s: missing sapling anchor: %s \n", __FUNCTION__, spendDescription.anchor.GetHex().c_str()); LogPrintf("%s: missing sapling anchor: %s in tx %s \n", __FUNCTION__, spendDescription.anchor.GetHex().c_str(), tx.GetHash().GetHex().c_str());
return false; return false;
} }
} }

View File

@@ -614,7 +614,7 @@ int32_t hush_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryi
notarized = 1; notarized = 1;
if ( strcmp("DPOW",ccdata.symbol) == 0 || strncmp("ZPOW",ccdata.symbol,5) == 0 || strcmp("TUSH",ccdata.symbol) == 0) if ( strcmp("DPOW",ccdata.symbol) == 0 || strncmp("ZPOW",ccdata.symbol,5) == 0 || strcmp("TUSH",ccdata.symbol) == 0)
notarized = 1; notarized = 1;
if ( 0 && opretlen != 149 ) if ( opretlen != 149 )
printf("[%s].%d (%s) matched.%d i.%d j.%d notarized.%d %llx opretlen.%d len.%d offset.%d opoffset.%d\n",SMART_CHAIN_SYMBOL,height,ccdata.symbol,matched,i,j,notarized,(long long)signedmask,opretlen,len,offset,opoffset); printf("[%s].%d (%s) matched.%d i.%d j.%d notarized.%d %llx opretlen.%d len.%d offset.%d opoffset.%d\n",SMART_CHAIN_SYMBOL,height,ccdata.symbol,matched,i,j,notarized,(long long)signedmask,opretlen,len,offset,opoffset);
len += dragon_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&srchash); len += dragon_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&srchash);
len += dragon_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp); len += dragon_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp);
@@ -637,7 +637,7 @@ int32_t hush_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryi
ccdata.MoMdata.notarized_height = *notarizedheightp; ccdata.MoMdata.notarized_height = *notarizedheightp;
ccdata.MoMdata.height = height; ccdata.MoMdata.height = height;
ccdata.MoMdata.txi = i; ccdata.MoMdata.txi = i;
//printf("nameoffset.%d len.%d + 36 %d opoffset.%d vs opretlen.%d\n",nameoffset,len,len+36,opoffset,opretlen); printf("nameoffset.%d len.%d + 36 %d opoffset.%d vs opretlen.%d\n",nameoffset,len,len+36,opoffset,opretlen);
if ( len+36-opoffset <= opretlen ) if ( len+36-opoffset <= opretlen )
{ {
len += dragon_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&MoM); len += dragon_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&MoM);
@@ -647,8 +647,8 @@ int32_t hush_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryi
if ( len+sizeof(ccdata.CCid)-opoffset <= opretlen ) if ( len+sizeof(ccdata.CCid)-opoffset <= opretlen )
{ {
len += dragon_rwnum(0,&scriptbuf[len],sizeof(ccdata.CCid),(uint8_t *)&ccdata.CCid); len += dragon_rwnum(0,&scriptbuf[len],sizeof(ccdata.CCid),(uint8_t *)&ccdata.CCid);
//if ( ((MoMdepth>>16) & 0xffff) != (ccdata.CCid & 0xffff) ) if ( ((MoMdepth>>16) & 0xffff) != (ccdata.CCid & 0xffff) )
// fprintf(stderr,"%s CCid mismatch %u != %u\n",SMART_CHAIN_SYMBOL,((MoMdepth>>16) & 0xffff),(ccdata.CCid & 0xffff)); fprintf(stderr,"%s CCid mismatch %u != %u\n",SMART_CHAIN_SYMBOL,((MoMdepth>>16) & 0xffff),(ccdata.CCid & 0xffff));
ccdata.len = sizeof(ccdata.CCid); ccdata.len = sizeof(ccdata.CCid);
if ( SMART_CHAIN_SYMBOL[0] != 0 ) if ( SMART_CHAIN_SYMBOL[0] != 0 )
{ {
@@ -706,7 +706,7 @@ int32_t hush_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryi
printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d) MoM.%s %d\n",SMART_CHAIN_SYMBOL,height,sp->NOTARIZED_HEIGHT,SMART_CHAIN_SYMBOL,srchash.ToString().c_str(),"HUSH",desttxid.ToString().c_str(),opretlen,len,sp->MoM.ToString().c_str(),sp->MoMdepth); printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d) MoM.%s %d\n",SMART_CHAIN_SYMBOL,height,sp->NOTARIZED_HEIGHT,SMART_CHAIN_SYMBOL,srchash.ToString().c_str(),"HUSH",desttxid.ToString().c_str(),opretlen,len,sp->MoM.ToString().c_str(),sp->MoMdepth);
} //else if ( fJustCheck ) } //else if ( fJustCheck )
// return (-3); // if the notarisation is only invalid because its out of order it cannot be mined in a block with a valid one! // return (-3); // if the notarization is only invalid because its out of order it cannot be mined in a block with a valid one!
} else if ( opretlen != 149 && height > 600000 && matched != 0 ) } else if ( opretlen != 149 && height > 600000 && matched != 0 )
printf("%s validated.%d notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s len.%d opretlen.%d\n",ccdata.symbol,validated,notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,SMART_CHAIN_SYMBOL,srchash.ToString().c_str(),desttxid.ToString().c_str(),len,opretlen); printf("%s validated.%d notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s len.%d opretlen.%d\n",ccdata.symbol,validated,notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,SMART_CHAIN_SYMBOL,srchash.ToString().c_str(),desttxid.ToString().c_str(),len,opretlen);
} }
@@ -766,7 +766,7 @@ int32_t hush_notarycmp(uint8_t *scriptPubKey,int32_t scriptlen,uint8_t pubkeys[6
int32_t hush_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) int32_t hush_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block)
{ {
static int32_t hwmheight; static int32_t hwmheight;
std::vector<int32_t> notarisations; std::vector<int32_t> notarizations;
uint64_t signedmask,voutmask; char symbol[HUSH_SMART_CHAIN_MAXLEN],dest[HUSH_SMART_CHAIN_MAXLEN]; struct hush_state *sp; uint64_t signedmask,voutmask; char symbol[HUSH_SMART_CHAIN_MAXLEN],dest[HUSH_SMART_CHAIN_MAXLEN]; struct hush_state *sp;
uint8_t scriptbuf[10001],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 zero,btctxid,txhash; uint8_t scriptbuf[10001],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 zero,btctxid,txhash;
int32_t i,j,k,numnotaries,notarized,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; int32_t i,j,k,numnotaries,notarized,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count;
@@ -899,8 +899,8 @@ int32_t hush_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block)
notaryid = hush_voutupdate(fJustCheck,&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,&notarizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.LastTip()->GetBlockTime()); notaryid = hush_voutupdate(fJustCheck,&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,&notarizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.LastTip()->GetBlockTime());
if ( fJustCheck && notaryid == -2 ) if ( fJustCheck && notaryid == -2 )
{ {
// We see a valid notarisation here, save its location. // We see a valid notarization here, save its location.
notarisations.push_back(i); notarizations.push_back(i);
} }
if ( 0 && i > 0 ) if ( 0 && i > 0 )
{ {
@@ -963,11 +963,11 @@ int32_t hush_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block)
//fprintf(stderr,"%s end connect.%d\n",SMART_CHAIN_SYMBOL,pindex->GetHeight()); //fprintf(stderr,"%s end connect.%d\n",SMART_CHAIN_SYMBOL,pindex->GetHeight());
if (fJustCheck) if (fJustCheck)
{ {
if ( notarisations.size() == 0 ) if ( notarizations.size() == 0 )
return(0); return(0);
if ( notarisations.size() == 1 && notarisations[0] == 1 ) if ( notarizations.size() == 1 && notarizations[0] == 1 )
return(1); return(1);
if ( notarisations.size() > 1 || (notarisations.size() == 1 && notarisations[0] != 1) ) if ( notarizations.size() > 1 || (notarizations.size() == 1 && notarizations[0] != 1) )
return(-1); return(-1);
fprintf(stderr,"hush_connectblock: unxexpected behaviour when fJustCheck == true, report bug plz ! \n"); fprintf(stderr,"hush_connectblock: unxexpected behaviour when fJustCheck == true, report bug plz ! \n");

View File

@@ -1375,7 +1375,7 @@ uint64_t hush_notarypayamount(int32_t nHeight, int64_t notarycount)
int32_t hush_getnotarizedheight(uint32_t timestamp,int32_t height, uint8_t *script, int32_t len) int32_t hush_getnotarizedheight(uint32_t timestamp,int32_t height, uint8_t *script, int32_t len)
{ {
// Check the notarisation is valid, and extract notarised height. // Check the notarization is valid, and extract notarized height.
uint64_t voutmask; uint64_t voutmask;
uint8_t scriptbuf[10001]; uint8_t scriptbuf[10001];
int32_t isratification,specialtx,notarizedheight; int32_t isratification,specialtx,notarizedheight;
@@ -1403,7 +1403,7 @@ uint64_t hush_notarypay(CMutableTransaction &txNew, std::vector<int8_t> &Notariz
if ( notarypubkeys[0][0] == 0 ) if ( notarypubkeys[0][0] == 0 )
return(0); return(0);
// Check the notarisation is valid. // Check the notarization is valid.
int32_t notarizedheight = hush_getnotarizedheight(timestamp, height, script, len); int32_t notarizedheight = hush_getnotarizedheight(timestamp, height, script, len);
if ( notarizedheight == 0 ) if ( notarizedheight == 0 )
return(0); return(0);
@@ -1416,7 +1416,7 @@ uint64_t hush_notarypay(CMutableTransaction &txNew, std::vector<int8_t> &Notariz
if ( AmountToPay == 0 ) if ( AmountToPay == 0 )
return(0); return(0);
// loop over notarisation vins and add transaction to coinbase. // loop over notarization vins and add transaction to coinbase.
// Commented prints here can be used to verify manually the pubkeys match. // Commented prints here can be used to verify manually the pubkeys match.
for (int8_t n = 0; n < NotarizationNotaries.size(); n++) for (int8_t n = 0; n < NotarizationNotaries.size(); n++)
{ {
@@ -1468,10 +1468,10 @@ uint64_t hush_checknotarypay(CBlock *pblock,int32_t height)
if ( !GetNotarizationNotaries(notarypubkeys, numSN, pblock->vtx[1].vin, NotarizationNotaries) ) if ( !GetNotarizationNotaries(notarypubkeys, numSN, pblock->vtx[1].vin, NotarizationNotaries) )
return(0); return(0);
// check a notary didnt sign twice (this would be an invalid notarisation later on and cause problems) // check a notary didnt sign twice (this would be an invalid notarization later on and cause problems)
std::set<int> checkdupes( NotarizationNotaries.begin(), NotarizationNotaries.end() ); std::set<int> checkdupes( NotarizationNotaries.begin(), NotarizationNotaries.end() );
if ( checkdupes.size() != NotarizationNotaries.size() ) { if ( checkdupes.size() != NotarizationNotaries.size() ) {
fprintf(stderr, "Possible notarisation is signed multiple times by same notary. It is invalid.\n"); fprintf(stderr, "Possible notarization is signed multiple times by same notary. It is invalid.\n");
return(0); return(0);
} }
const CChainParams& chainparams = Params(); const CChainParams& chainparams = Params();
@@ -1480,7 +1480,7 @@ uint64_t hush_checknotarypay(CBlock *pblock,int32_t height)
CMutableTransaction txNew = CreateNewContextualCMutableTransaction(consensusParams, height); CMutableTransaction txNew = CreateNewContextualCMutableTransaction(consensusParams, height);
if ( pblock->vtx[1].vout.size() == 2 && pblock->vtx[1].vout[1].nValue == 0 ) if ( pblock->vtx[1].vout.size() == 2 && pblock->vtx[1].vout[1].nValue == 0 )
{ {
// Get the OP_RETURN for the notarisation // Get the OP_RETURN for the notarization
uint8_t *script = (uint8_t *)&pblock->vtx[1].vout[1].scriptPubKey[0]; uint8_t *script = (uint8_t *)&pblock->vtx[1].vout[1].scriptPubKey[0];
int32_t scriptlen = (int32_t)pblock->vtx[1].vout[1].scriptPubKey.size(); int32_t scriptlen = (int32_t)pblock->vtx[1].vout[1].scriptPubKey.size();
if ( script[0] == OP_RETURN ) if ( script[0] == OP_RETURN )
@@ -1491,13 +1491,13 @@ uint64_t hush_checknotarypay(CBlock *pblock,int32_t height)
} }
else else
{ {
fprintf(stderr, "vout 2 of notarisation is not OP_RETURN scriptlen.%i\n", scriptlen); fprintf(stderr, "vout 2 of notarization is not OP_RETURN scriptlen.%i\n", scriptlen);
return(0); return(0);
} }
} else return(0); } else return(0);
// if notarypay fails, because the notarisation is not valid, exit now as txNew was not created. // if notarypay fails, because the notarization is not valid, exit now as txNew was not created.
// This should never happen, as the notarisation is checked before this function is called. // This should never happen, as the notarization is checked before this function is called.
if ( totalsats == 0 ) if ( totalsats == 0 )
{ {
fprintf(stderr, "notary pay returned 0!\n"); fprintf(stderr, "notary pay returned 0!\n");
@@ -1519,7 +1519,7 @@ uint64_t hush_checknotarypay(CBlock *pblock,int32_t height)
n++; n++;
continue; continue;
} }
// Check the pubkeys match the pubkeys in the notarisation. // Check the pubkeys match the pubkeys in the notarization.
script = (uint8_t *)&txout.scriptPubKey[0]; script = (uint8_t *)&txout.scriptPubKey[0];
scriptlen = (int32_t)txout.scriptPubKey.size(); scriptlen = (int32_t)txout.scriptPubKey.size();
if ( scriptlen == 35 && script[0] == 33 && script[34] == OP_CHECKSIG && memcmp(script+1,notarypubkeys[NotarizationNotaries[n-1]],33) == 0 ) if ( scriptlen == 35 && script[0] == 33 && script[34] == OP_CHECKSIG && memcmp(script+1,notarypubkeys[NotarizationNotaries[n-1]],33) == 0 )
@@ -1537,7 +1537,7 @@ uint64_t hush_checknotarypay(CBlock *pblock,int32_t height)
} }
if ( matches != 0 && matches == NotarizationNotaries.size() && totalsats == total ) if ( matches != 0 && matches == NotarizationNotaries.size() && totalsats == total )
{ {
//fprintf(stderr, "Validated coinbase matches notarisation in tx position 1.\n" ); //fprintf(stderr, "Validated coinbase matches notarization in tx position 1.\n" );
return(totalsats); return(totalsats);
} }
return(0); return(0);
@@ -1757,10 +1757,10 @@ int32_t hush_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
// We check the full validation in ConnectBlock directly to get the amount for coinbase. So just approx here. // We check the full validation in ConnectBlock directly to get the amount for coinbase. So just approx here.
if ( slowflag == 0 && pblock->vtx[0].vout.size() > 1 ) if ( slowflag == 0 && pblock->vtx[0].vout.size() > 1 )
{ {
// Check the notarisation tx is to the crypto address. // Check the notarization tx is to the crypto address.
if ( !hush_is_notarytx(pblock->vtx[1]) == 1 ) if ( !hush_is_notarytx(pblock->vtx[1]) == 1 )
{ {
fprintf(stderr, "notarisation is not to crypto address ht.%i\n",height); fprintf(stderr, "notarization is not to crypto address ht.%i\n",height);
return(-1); return(-1);
} }
// Check min sigs. // Check min sigs.

View File

@@ -1452,7 +1452,7 @@ bool CheckTransaction(uint32_t tiptime,const CTransaction& tx, CValidationState
return true; return true;
} }
// This is used only in RPC currently but hush_notaries()/gethushseason/getacseason is consensus // This is and hush_notaries()/gethushseason/getacseason are all consensus code
int32_t hush_isnotaryvout(char *coinaddr,uint32_t tiptime) { int32_t hush_isnotaryvout(char *coinaddr,uint32_t tiptime) {
bool ishush3 = strncmp(SMART_CHAIN_SYMBOL, "HUSH3",5) == 0 ? true : false; bool ishush3 = strncmp(SMART_CHAIN_SYMBOL, "HUSH3",5) == 0 ? true : false;
bool istush = strncmp(SMART_CHAIN_SYMBOL, "TUSH",4) == 0 ? true : false; bool istush = strncmp(SMART_CHAIN_SYMBOL, "TUSH",4) == 0 ? true : false;
@@ -5603,7 +5603,7 @@ bool PruneOneBlockFile(bool tempfile, const int fileNumber)
} }
else else
{ {
// Block is not in main chain and is older than last notarised block so its safe for removal. // Block is not in main chain and is older than last notarized block so its safe for removal.
fprintf(stderr, "Block [%i] in tempfile.%i We can clear this block!\n",pindex->GetHeight(),fileNumber); fprintf(stderr, "Block [%i] in tempfile.%i We can clear this block!\n",pindex->GetHeight(),fileNumber);
// Add index to list and remove after loop? // Add index to list and remove after loop?
} }

View File

@@ -20,9 +20,9 @@ typedef std::vector<Notarization> NotarizationsInBlock;
NotarizationsInBlock ScanBlockNotarizations(const CBlock &block, int nHeight); NotarizationsInBlock ScanBlockNotarizations(const CBlock &block, int nHeight);
bool GetBlockNotarizations(uint256 blockHash, NotarizationsInBlock &nibs); bool GetBlockNotarizations(uint256 blockHash, NotarizationsInBlock &nibs);
bool GetBackNotarization(uint256 notarisationHash, Notarization &n); bool GetBackNotarization(uint256 notarizationHash, Notarization &n);
void WriteBackNotarizations(const NotarizationsInBlock notarisations, CDBBatch &batch); void WriteBackNotarizations(const NotarizationsInBlock notarizations, CDBBatch &batch);
void EraseBackNotarizations(const NotarizationsInBlock notarisations, CDBBatch &batch); void EraseBackNotarizations(const NotarizationsInBlock notarizations, CDBBatch &batch);
int ScanNotarizationsDB(int height, std::string symbol, int scanLimitBlocks, Notarization& out); int ScanNotarizationsDB(int height, std::string symbol, int scanLimitBlocks, Notarization& out);
#endif /* HUSH_NOTARISATIONDB_H */ #endif /* HUSH_NOTARISATIONDB_H */

View File

@@ -367,6 +367,7 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp, const CPubKey& my
"\nResult (if verbose > 0):\n" "\nResult (if verbose > 0):\n"
"{\n" "{\n"
" \"hex\" : \"data\", (string) The serialized, hex-encoded data for 'txid'\n" " \"hex\" : \"data\", (string) The serialized, hex-encoded data for 'txid'\n"
" \"size\" : n, (numeric) The length in bytes\n"
" \"txid\" : \"id\", (string) The transaction id (same as provided)\n" " \"txid\" : \"id\", (string) The transaction id (same as provided)\n"
" \"version\" : n, (numeric) The version\n" " \"version\" : n, (numeric) The version\n"
" \"locktime\" : ttt, (numeric) The lock time\n" " \"locktime\" : ttt, (numeric) The lock time\n"
@@ -453,6 +454,7 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp, const CPubKey& my
UniValue result(UniValue::VOBJ); UniValue result(UniValue::VOBJ);
result.push_back(Pair("hex", strHex)); result.push_back(Pair("hex", strHex));
result.push_back(Pair("size", GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION) ));
TxToJSONExpanded(tx, hashBlock, result, nHeight, nConfirmations, nBlockTime); TxToJSONExpanded(tx, hashBlock, result, nHeight, nConfirmations, nBlockTime);
return result; return result;
} }
@@ -647,7 +649,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp, const CPubKey&
"2. \"outputs\" (object, required) a json object with outputs\n" "2. \"outputs\" (object, required) a json object with outputs\n"
" {\n" " {\n"
" \"address\": x.xxx, (numeric or string, required) The key is the HUSH address or script (in hex), the numeric value (can be string) is the " + CURRENCY_UNIT + " amount\n" " \"address\": x.xxx, (numeric or string, required) The key is the HUSH address or script (in hex), the numeric value (can be string) is the " + CURRENCY_UNIT + " amount\n"
" \"data\": \"hex\" (string, required) The key is \"data\", the value is hex encoded data\n" " \"data\": \"hex\" (string, optional) The key is \"data\", the value is hex encoded OP_RETURN data\n"
" ,...\n" " ,...\n"
" }\n" " }\n"
"3. locktime (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs\n" "3. locktime (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs\n"

View File

@@ -479,8 +479,6 @@ extern UniValue z_listoperationids(const UniValue& params, bool fHelp, const CPu
extern UniValue opreturn_burn(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp extern UniValue opreturn_burn(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp
extern UniValue rescan(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp extern UniValue rescan(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp
extern UniValue z_validateaddress(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcmisc.cpp extern UniValue z_validateaddress(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcmisc.cpp
extern UniValue z_getpaymentdisclosure(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcdisclosure.cpp
extern UniValue z_validatepaymentdisclosure(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcdisclosure.cpp
extern UniValue MoMoMdata(const UniValue& params, bool fHelp, const CPubKey& mypk); extern UniValue MoMoMdata(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue calc_MoM(const UniValue& params, bool fHelp, const CPubKey& mypk); extern UniValue calc_MoM(const UniValue& params, bool fHelp, const CPubKey& mypk);

View File

@@ -123,9 +123,9 @@ public:
return true; return true;
} }
bool GetNotarizationData(uint256 notarisationHash, NotarizationData &data) const bool GetNotarizationData(uint256 notarizationHash, NotarizationData &data) const
{ {
if (notarisationHash == NotarizationHash()) { if (notarizationHash == NotarizationHash()) {
data.MoM = MoM; data.MoM = MoM;
return true; return true;
} }
@@ -567,7 +567,7 @@ TEST_F(TestBet, testImportPayoutInvalidNotarizationHash)
EvalMock eval = ebet.SetEvalMock(12); EvalMock eval = ebet.SetEvalMock(12);
MoMProof proof = ebet.GetMoMProof(); MoMProof proof = ebet.GetMoMProof();
proof.notarisationHash = uint256(); proof.notarizationHash = uint256();
CMutableTransaction importTx = ebet.bet.MakeImportPayoutTx( CMutableTransaction importTx = ebet.bet.MakeImportPayoutTx(
ebet.Payouts(Player2), ebet.DisputeTx(Player2), uint256(), proof); ebet.Payouts(Player2), ebet.DisputeTx(Player2), uint256(), proof);

View File

@@ -49,6 +49,6 @@ TEST(TestParseNotarization, test__b)
// for l in `g 'parse notarisation' ~/.hush/HUSH3/debug.log | pyline 'l.split()[8]'`; do hoek decodeTx '{"hex":"'`src/hush-cli getrawtransaction "$l"`'"}' | jq '.outputs[1].script.op_return' | pyline 'import base64; print base64.b64decode(l).encode("hex")'; done // for l in `g 'parse notarization' ~/.hush/HUSH3/debug.log | pyline 'l.split()[8]'`; do hoek decodeTx '{"hex":"'`src/hush-cli getrawtransaction "$l"`'"}' | jq '.outputs[1].script.op_return' | pyline 'import base64; print base64.b64decode(l).encode("hex")'; done
} }

View File

@@ -64,7 +64,7 @@ const std::string ADDR_TYPE_AMNESIA = "amnesia";
extern int32_t HUSH_INSYNC; extern int32_t HUSH_INSYNC;
uint32_t hush_segid32(char *coinaddr); uint32_t hush_segid32(char *coinaddr);
int32_t hush_dpowconfs(int32_t height,int32_t numconfs); int32_t hush_dpowconfs(int32_t height,int32_t numconfs);
int32_t hush_isnotaryvout(char *coinaddr,uint32_t tiptime); // from ac_private chains only int32_t hush_isnotaryvout(char *coinaddr,uint32_t tiptime); // needed for ac_private=1 chains only
CBlockIndex *hush_getblockindex(uint256 hash); CBlockIndex *hush_getblockindex(uint256 hash);
extern string randomSietchZaddr(); extern string randomSietchZaddr();
extern CAmount fConsolidationTxFee; extern CAmount fConsolidationTxFee;
@@ -559,9 +559,9 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp, const CPubKey& mypk)
"\"transactionid\" (string) The transaction id.\n" "\"transactionid\" (string) The transaction id.\n"
"\nExamples:\n" "\nExamples:\n"
+ HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1") + HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1")
+ HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1 \"donation\" \"seans outpost\"") + HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1 \"donation\" \"Hush Puppy Freedom Fund\"")
+ HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1 \"\" \"\" true") + HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1 \"\" \"\" true")
+ HelpExampleRpc("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", 0.1, \"donation\", \"seans outpost\"") + HelpExampleRpc("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", 0.1, \"donation\", \"Hush Puppy Freedom Fund\"")
); );
if ( ASSETCHAINS_PRIVATE != 0 && AmountFromValue(params[1]) > 0 ) if ( ASSETCHAINS_PRIVATE != 0 && AmountFromValue(params[1]) > 0 )
@@ -1502,8 +1502,6 @@ UniValue sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk)
"\nAs a json rpc call\n" "\nAs a json rpc call\n"
+ HelpExampleRpc("sendmany", "\"\", {\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\":0.01,\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\":0.02}, 6, \"testing\"") + HelpExampleRpc("sendmany", "\"\", {\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\":0.01,\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\":0.02}, 6, \"testing\"")
); );
if ( ASSETCHAINS_PRIVATE != 0 )
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain");
LOCK2(cs_main, pwalletMain->cs_wallet); LOCK2(cs_main, pwalletMain->cs_wallet);
@@ -1528,6 +1526,17 @@ UniValue sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk)
std::vector<std::string> keys = sendTo.getKeys(); std::vector<std::string> keys = sendTo.getKeys();
int32_t i = 0; int32_t i = 0;
for (const std::string& name_ : keys) { for (const std::string& name_ : keys) {
// Allow transparent notary addresses and throw an error for anything else
// This is also a consensus check but we want to prevent it from going into the mempool
// and give an error as early as possible
if ( ASSETCHAINS_PRIVATE != 0 )
{
if ( hush_isnotaryvout((char *)name_.c_str(),chainActive.LastTip()->nTime) == 0 )
{
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transparent " + strprintf("%s",hush_chainname()) + " address not allowed on private chain");
}
}
CTxDestination dest = DecodeDestination(name_); CTxDestination dest = DecodeDestination(name_);
if (!IsValidDestination(dest)) { if (!IsValidDestination(dest)) {
CScript tmpspk; CScript tmpspk;
@@ -3643,6 +3652,145 @@ UniValue z_listsentbyaddress(const UniValue& params, bool fHelp,const CPubKey&)
return ret; return ret;
} }
UniValue z_anonsetblockdelta(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
"z_anonsetblockdelta\n"
"\nReturns delta (difference) in the anonset for a given block height. A delta > 0 increases the anonset,\n"
"\na delta < 0 reduces the anonset and a delta=0 leaves the anonset the same. Given a single block height\n"
"\nwe calculate the delta for that block. Given two block heights, we calculate the delta for that range of blocks.\n"
"\nArguments:\n"
"1. \"height\" (number, required) The block height\n"
"1. \"end_height\" (number, optional) The ending block height\n"
"\nResult:\n"
"\"delta\" (integer) An integer number.\n"
"\nExamples:\n"
+ HelpExampleCli("z_anonsetblockdelta 123", "456")
+ HelpExampleRpc("z_anonsetblockdelta 123", "456")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
std::string strHeight = params[0].get_str();
int nHeight = -1;
try {
nHeight = std::stoi(strHeight);
} catch (const std::exception &e) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block height parameter");
}
if (nHeight < 0 || nHeight > chainActive.Height()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
}
auto strHash = chainActive[nHeight]->GetBlockHash().GetHex();
uint256 hash(uint256S(strHash));
if (mapBlockIndex.count(hash) == 0)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
CBlock block;
CBlockIndex* pblockindex = mapBlockIndex[hash];
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)");
if(!ReadBlockFromDisk(block, pblockindex,1))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
int delta = 0;
// given a single block height, we calculate delta for that height
if (params.size() == 1) {
BOOST_FOREACH(const CTransaction&tx, block.vtx)
{
// delta = shielded outputs - shielded inputs
if(!tx.IsCoinBase()) {
delta += tx.vShieldedOutput.size() - tx.vShieldedSpend.size();
}
}
} else {
// given two blocks, we calculate delta for that range
std::string strHeight2 = params[1].get_str();
int nHeight2 = -1;
try {
nHeight2 = std::stoi(strHeight2);
} catch (const std::exception &e) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid ending block height parameter");
}
if (nHeight2 <= nHeight) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Ending block height must be larger than starting height");
}
if (nHeight2 < 0 || nHeight2 > chainActive.Height()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Ending block height out of range");
}
// get the delta for every block in the range
for(int currentHeight = nHeight; currentHeight <= nHeight2; currentHeight++) {
auto strHash = chainActive[currentHeight]->GetBlockHash().GetHex();
uint256 hash(uint256S(strHash));
if (mapBlockIndex.count(hash) == 0)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
CBlock block;
CBlockIndex* pblockindex = mapBlockIndex[hash];
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)");
if(!ReadBlockFromDisk(block, pblockindex,1))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
BOOST_FOREACH(const CTransaction&tx, block.vtx)
{
// delta = shielded outputs - shielded inputs
if(!tx.IsCoinBase()) {
delta += tx.vShieldedOutput.size() - tx.vShieldedSpend.size();
}
}
}
}
return delta;
}
UniValue z_anonsettxdelta(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() != 1)
throw runtime_error(
"z_anonsettxdelta\n"
"\nReturns delta (difference) in the anonset for a given txid. A delta > 0 increases the anonset,\n"
"\na delta < 0 reduces the anonset and a delta=0 leaves the anonset the same.\n"
"\nArguments:\n"
"1. \"txid\" (string, required) The transaction id\n"
"\nResult:\n"
"\"delta\" (integer) An integer number.\n"
"\nExamples:\n"
+ HelpExampleCli("z_anonsettxdelta txid", "123")
+ HelpExampleRpc("z_anonsettxdelta txid", "123")
);
uint256 txid,hashBlock;
CTransaction tx;
txid.SetHex(params[0].get_str());
LOCK(cs_main);
if (!GetTransaction(txid, tx, hashBlock, true))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction");
// delta = shielded outputs - shielded inputs
int delta = tx.vShieldedOutput.size() - tx.vShieldedSpend.size();
return delta;
}
UniValue z_getbalances(const UniValue& params, bool fHelp, const CPubKey& mypk) UniValue z_getbalances(const UniValue& params, bool fHelp, const CPubKey& mypk)
{ {
if (!EnsureWalletIsAvailable(fHelp)) if (!EnsureWalletIsAvailable(fHelp))
@@ -4929,6 +5077,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk)
if (fromTaddr) { if (fromTaddr) {
txsize += CTXIN_SPEND_DUST_SIZE; txsize += CTXIN_SPEND_DUST_SIZE;
//TODO: On HUSH since block 340k there can no longer be taddr change, //TODO: On HUSH since block 340k there can no longer be taddr change,
// (except for notary addresses)
// so we can likely make a better estimation of max txsize // so we can likely make a better estimation of max txsize
txsize += CTXOUT_REGULAR_SIZE; // There will probably be taddr change txsize += CTXOUT_REGULAR_SIZE; // There will probably be taddr change
} }
@@ -8342,6 +8491,8 @@ static const CRPCCommand commands[] =
{ "wallet", "z_listunspent", &z_listunspent, false }, { "wallet", "z_listunspent", &z_listunspent, false },
{ "wallet", "z_getbalance", &z_getbalance, false }, { "wallet", "z_getbalance", &z_getbalance, false },
{ "wallet", "z_getbalances", &z_getbalances, false }, { "wallet", "z_getbalances", &z_getbalances, false },
{ "wallet", "z_anonsettxdelta", &z_anonsettxdelta, true },
{ "wallet", "z_anonsetblockdelta", &z_anonsetblockdelta, true },
{ "wallet", "z_gettotalbalance", &z_gettotalbalance, false }, { "wallet", "z_gettotalbalance", &z_gettotalbalance, false },
{ "wallet", "z_mergetoaddress", &z_mergetoaddress, false }, { "wallet", "z_mergetoaddress", &z_mergetoaddress, false },
{ "wallet", "z_sendmany", &z_sendmany, false }, { "wallet", "z_sendmany", &z_sendmany, false },