@@ -3,6 +3,7 @@
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.authproxy import JSONRPCException
|
||||
from test_framework.util import assert_equal, assert_greater_than, \
|
||||
@@ -11,6 +12,8 @@ from test_framework.util import assert_equal, assert_greater_than, \
|
||||
|
||||
import time
|
||||
from decimal import Decimal
|
||||
from random import choice
|
||||
from string import ascii_uppercase
|
||||
|
||||
def assert_success(result):
|
||||
assert_equal(result['result'], 'success')
|
||||
@@ -18,6 +21,11 @@ def assert_success(result):
|
||||
def assert_error(result):
|
||||
assert_equal(result['result'], 'error')
|
||||
|
||||
def generate_random_string(length):
|
||||
random_string = ''.join(choice(ascii_uppercase) for i in range(length))
|
||||
return random_string
|
||||
|
||||
|
||||
class CryptoConditionsTest (BitcoinTestFramework):
|
||||
|
||||
def setup_chain(self):
|
||||
@@ -470,7 +478,6 @@ class CryptoConditionsTest (BitcoinTestFramework):
|
||||
result = rpc.tokenbalance(tokenid,randompubkey)
|
||||
assert_equal(result["balance"], 1)
|
||||
|
||||
|
||||
def run_rewards_tests(self):
|
||||
rpc = self.nodes[0]
|
||||
result = rpc.rewardsaddress()
|
||||
@@ -581,6 +588,51 @@ class CryptoConditionsTest (BitcoinTestFramework):
|
||||
result = rpc.rewardsunlock("STUFF", fundingtxid, locktxid)
|
||||
assert_error(result)
|
||||
|
||||
def run_oracles_tests(self):
|
||||
rpc = self.nodes[0]
|
||||
result = rpc.oraclesaddress()
|
||||
assert_success(result)
|
||||
for x in ['OraclesCCaddress', 'Oraclesmarker', 'myCCaddress', 'myaddress']:
|
||||
assert_equal(result[x][0], 'R')
|
||||
|
||||
result = rpc.oraclesaddress(self.pubkey)
|
||||
assert_success(result)
|
||||
for x in ['OraclesCCaddress', 'Oraclesmarker', 'myCCaddress', 'myaddress']:
|
||||
assert_equal(result[x][0], 'R')
|
||||
|
||||
# there are no oracles created yet
|
||||
result = rpc.oracleslist()
|
||||
assert_equal(result, [])
|
||||
|
||||
# looking up non-existent oracle should return error.
|
||||
result = rpc.oraclesinfo("none")
|
||||
assert_error(result)
|
||||
|
||||
# attempt to create oracle with not valid data type should return error
|
||||
result = rpc.oraclescreate("Test", "Test", "Test")
|
||||
assert_error(result)
|
||||
|
||||
# attempt to create oracle with description > 32 symbols should return error
|
||||
too_long_name = generate_random_string(33)
|
||||
result = rpc.oraclescreate(too_long_name, "Test", "s")
|
||||
|
||||
|
||||
# attempt to create oracle with description > 4096 symbols should return error
|
||||
too_long_description = generate_random_string(4100)
|
||||
result = rpc.oraclescreate("Test", too_long_description, "s")
|
||||
assert_error(result)
|
||||
|
||||
# valid creating oracles of different types
|
||||
# using such naming to re-use it for data publishing / reading (e.g. oracle_s for s type)
|
||||
valid_formats = ["s", "S", "d", "D", "c", "C", "t", "T", "i", "I", "l", "L", "h", "Ihh"]
|
||||
for f in valid_formats:
|
||||
result = rpc.oraclescreate("Test", "Test", f)
|
||||
assert_success(result)
|
||||
globals()["oracle_{}".format(f)] = self.send_and_mine(result['hex'])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def run_test (self):
|
||||
print("Mining blocks...")
|
||||
@@ -594,12 +646,13 @@ class CryptoConditionsTest (BitcoinTestFramework):
|
||||
print("Importing privkey")
|
||||
rpc.importprivkey(self.privkey)
|
||||
|
||||
# self.run_faucet_tests()
|
||||
#self.run_faucet_tests()
|
||||
self.run_rewards_tests()
|
||||
self.run_dice_tests()
|
||||
self.run_token_tests()
|
||||
self.run_faucet_tests()
|
||||
self.run_oracles_tests()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
CryptoConditionsTest ().main ()
|
||||
CryptoConditionsTest ().main()
|
||||
|
||||
@@ -267,7 +267,7 @@ libbitcoin_server_a_SOURCES = \
|
||||
cc/dice.cpp \
|
||||
cc/lotto.cpp \
|
||||
cc/fsm.cpp \
|
||||
cc/MofN.cpp \
|
||||
cc/heir.cpp \
|
||||
cc/oracles.cpp \
|
||||
cc/prices.cpp \
|
||||
cc/pegs.cpp \
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#!/bin/bash
|
||||
./komodo-cli -ac_name=DION $1 $2 $3 $4 $5 $6
|
||||
#!/bin/bash
|
||||
./komodo-cli -ac_name=DION $1 $2 $3 $4 $5 $6
|
||||
|
||||
@@ -176,18 +176,6 @@
|
||||
"190.114.254.104"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ac_name": "KMDICE",
|
||||
"ac_supply": "10500000",
|
||||
"ac_reward": "2500000000",
|
||||
"ac_halving": "210000",
|
||||
"ac_cc": "2",
|
||||
"addressindex": "1",
|
||||
"spentindex": "1",
|
||||
"addnode": [
|
||||
"144.76.217.232"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ac_name": "DION",
|
||||
"ac_supply": "3900000000",
|
||||
|
||||
@@ -62,8 +62,8 @@ void WaitForShutdown(boost::thread_group* threadGroup)
|
||||
}
|
||||
else
|
||||
{
|
||||
komodo_interestsum();
|
||||
komodo_longestchain();
|
||||
//komodo_interestsum();
|
||||
//komodo_longestchain();
|
||||
MilliSleep(20000);
|
||||
}
|
||||
fShutdown = ShutdownRequested();
|
||||
|
||||
@@ -95,7 +95,7 @@ EVAL(EVAL_DICE, 0xe6) \
|
||||
EVAL(EVAL_FSM, 0xe7) \
|
||||
EVAL(EVAL_AUCTION, 0xe8) \
|
||||
EVAL(EVAL_LOTTO, 0xe9) \
|
||||
EVAL(EVAL_MOFN, 0xea) \
|
||||
EVAL(EVAL_HEIR, 0xea) \
|
||||
EVAL(EVAL_CHANNELS, 0xeb) \
|
||||
EVAL(EVAL_ORACLES, 0xec) \
|
||||
EVAL(EVAL_PRICES, 0xed) \
|
||||
@@ -490,8 +490,61 @@ Now we can make the payment based on the hashvalue revealed at a specified depth
|
||||
|
||||
Payments at the speed of the mempool, protected by dPoW!
|
||||
|
||||
<details of rpc calls, vin/vout allocations, etc>
|
||||
RPC calls
|
||||
channelsopen:
|
||||
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
|
||||
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).
|
||||
Example - channelspayment b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440 20000000
|
||||
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.
|
||||
Example - channelsclose b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440
|
||||
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
|
||||
Example - channelsrefund b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440 bb0ea34f846247642684c7c541c435b06ee79e47893640e5d2e51023841677fd
|
||||
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)
|
||||
|
||||
VIN/VOUT allocation
|
||||
Open:
|
||||
vin.0: normal input
|
||||
vout.0: CC vout for channel funding on CC1of2 pubkey
|
||||
vout.1: CC vout marker to senders pubKey
|
||||
vout.2: CC vout marker to receiver pubkey
|
||||
vout.n-2: normal change
|
||||
vout.n-1: opreturn - 'O' zerotxid senderspubkey receiverspubkey totalnumberofpayments paymentamount hashchain
|
||||
|
||||
Payment
|
||||
vin.0: normal input
|
||||
vin.1: CC input from channel funding
|
||||
vin.2: CC input from src marker
|
||||
vout.0: CC vout change to channel funding on CC1of2 pubkey
|
||||
vout.1: CC vout marker to senders pubKey
|
||||
vout.2: CC vout marker to receiver pubkey
|
||||
vout.3: normal output of payment amount to receiver pubkey
|
||||
vout.n-2: normal change
|
||||
vout.n-1: opreturn - 'P' opentxid senderspubkey receiverspubkey depth numpayments secret
|
||||
|
||||
Close:
|
||||
vin.0: normal input
|
||||
vin.1: CC input from channel funding
|
||||
vin.2: CC input from src marker
|
||||
vout.0: CC vout for channel funding
|
||||
vout.1: CC vout marker to senders pubKey
|
||||
vout.2: CC vout marker to receiver pubkey
|
||||
vout.n-2: normal change
|
||||
vout.n-1: opreturn - 'C' opentxid senderspubkey receiverspubkey 0 0 0
|
||||
|
||||
Refund:
|
||||
vin.0: normal input
|
||||
vin.1: CC input from channel funding
|
||||
vin.2: CC input from src marker
|
||||
vout.0: CC vout marker to senders pubKey
|
||||
vout.1: CC vout marker to receiver pubKey
|
||||
vout.2: normal output of CC input to senders pubkey
|
||||
vout.n-2: normal change
|
||||
vout.n-1: opreturn - 'R' opentxid senderspubkey receiverspubkey numpayments payment closetxid
|
||||
|
||||
Chapter 11 - oracles example
|
||||
Oracles CC is an example where it ended up being simpler than I first expected, but at the same time a lot more powerful. It is one of the smaller CC, but it enables creation of an arbitrary number of data markets, in a performant way.
|
||||
|
||||
@@ -24,10 +24,11 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &
|
||||
std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector<CPubKey> pubkeys);
|
||||
std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std::string refcoin,uint256 cointxid,int32_t claimvout,std::string deposithex,std::vector<uint8_t>proof,CPubKey destpub,int64_t amount);
|
||||
std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount);
|
||||
std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,std::vector<uint8_t> withdrawpub,int64_t amount);
|
||||
std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,CPubKey withdrawpub,int64_t amount);
|
||||
UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin);
|
||||
std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid,std::string refcoin,uint256 cointxid);
|
||||
std::string GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,uint256 withdrawtxid,char *txidaddr);
|
||||
UniValue GatewaysMultisig(char *txidaddr);
|
||||
std::string GatewaysPartialSign(uint64_t txfee,uint256 txidaddr,std::string refcoin, std::string hex);
|
||||
|
||||
// CCcustom
|
||||
UniValue GatewaysInfo(uint256 bindtxid);
|
||||
|
||||
@@ -14,16 +14,16 @@
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#ifndef CC_MOFN_H
|
||||
#define CC_MOFN_H
|
||||
#ifndef CC_HEIR_H
|
||||
#define CC_HEIR_H
|
||||
|
||||
#include "CCinclude.h"
|
||||
|
||||
#define EVAL_MOFN 0xea
|
||||
#define EVAL_HEIR 0xea
|
||||
|
||||
bool MofNValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx);
|
||||
bool HeirValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx);
|
||||
|
||||
// CCcustom
|
||||
UniValue MofNInfo();
|
||||
UniValue HeirInfo();
|
||||
|
||||
#endif
|
||||
@@ -17,15 +17,17 @@
|
||||
|
||||
int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs)
|
||||
{
|
||||
char coinaddr[64],destaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector<uint8_t> origpubkey; CTransaction vintx; int32_t j,vout,n = 0;
|
||||
char coinaddr[64],destaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector<uint8_t> origpubkey; CTransaction vintx; int32_t j,vout,n = 0;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
GetCCaddress(cp,coinaddr,pk);
|
||||
SetCCunspents(unspentOutputs,coinaddr);
|
||||
|
||||
threshold = total/(maxinputs!=0?maxinputs:64);
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
vout = (int32_t)it->first.index;
|
||||
if ( it->second.satoshis < threshold )
|
||||
continue;
|
||||
for (j=0; j<mtx.vin.size(); j++)
|
||||
if ( txid == mtx.vin[j].prevout.hash && vout == mtx.vin[j].prevout.n )
|
||||
break;
|
||||
|
||||
@@ -22,12 +22,11 @@
|
||||
|
||||
bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx);
|
||||
std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment);
|
||||
std::string ChannelStop(uint64_t txfee,CPubKey destpub,uint256 origtxid);
|
||||
std::string ChannelPayment(uint64_t txfee,uint256 prevtxid,uint256 origtxid,int32_t n,int64_t amount);
|
||||
std::string ChannelCollect(uint64_t txfee,uint256 paytxid,uint256 origtxid,int32_t n,int64_t amount);
|
||||
std::string ChannelRefund(uint64_t txfee,uint256 stoptxid,uint256 origtxid);
|
||||
std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint256 secret);
|
||||
std::string ChannelClose(uint64_t txfee,uint256 opentxid);
|
||||
std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid);
|
||||
|
||||
// CCcustom
|
||||
UniValue ChannelsInfo();
|
||||
UniValue ChannelsInfo(uint256 opentxid);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "CCauction.h"
|
||||
#include "CClotto.h"
|
||||
#include "CCfsm.h"
|
||||
#include "CCMofN.h"
|
||||
#include "CCHeir.h"
|
||||
#include "CCchannels.h"
|
||||
#include "CCOracles.h"
|
||||
#include "CCPrices.h"
|
||||
@@ -133,13 +133,13 @@ uint8_t AuctionCCpriv[32] = { 0x8c, 0x1b, 0xb7, 0x8c, 0x02, 0xa3, 0x9d, 0x21, 0x
|
||||
#undef FUNCNAME
|
||||
#undef EVALCODE
|
||||
|
||||
// MofN
|
||||
#define FUNCNAME IsMofNInput
|
||||
#define EVALCODE EVAL_MOFN
|
||||
const char *MofNCCaddr = "RDVHcSekmXgeYBqRupNTmqo3Rn8QRXNduy";
|
||||
const char *MofNNormaladdr = "RTPwUjKYECcGn6Y4KYChLhgaht1RSU4jwf";
|
||||
char MofNCChexstr[67] = { "03c91bef3d7cc59c3a89286833a3446b29e52a5e773f738a1ad2b09785e5f4179e" };
|
||||
uint8_t MofNCCpriv[32] = { 0x9d, 0xa1, 0xf8, 0xf7, 0xba, 0x0a, 0x91, 0x36, 0x89, 0x9a, 0x86, 0x30, 0x63, 0x20, 0xd7, 0xdf, 0xaa, 0x35, 0xe3, 0x99, 0x32, 0x2b, 0x63, 0xc0, 0x66, 0x9c, 0x93, 0xc4, 0x5e, 0x9d, 0xb9, 0xce };
|
||||
// Heir
|
||||
#define FUNCNAME IsHeirInput
|
||||
#define EVALCODE EVAL_HEIR
|
||||
const char *HeirCCaddr = "RDVHcSekmXgeYBqRupNTmqo3Rn8QRXNduy";
|
||||
const char *HeirNormaladdr = "RTPwUjKYECcGn6Y4KYChLhgaht1RSU4jwf";
|
||||
char HeirCChexstr[67] = { "03c91bef3d7cc59c3a89286833a3446b29e52a5e773f738a1ad2b09785e5f4179e" };
|
||||
uint8_t HeirCCpriv[32] = { 0x9d, 0xa1, 0xf8, 0xf7, 0xba, 0x0a, 0x91, 0x36, 0x89, 0x9a, 0x86, 0x30, 0x63, 0x20, 0xd7, 0xdf, 0xaa, 0x35, 0xe3, 0x99, 0x32, 0x2b, 0x63, 0xc0, 0x66, 0x9c, 0x93, 0xc4, 0x5e, 0x9d, 0xb9, 0xce };
|
||||
#include "CCcustom.inc"
|
||||
#undef FUNCNAME
|
||||
#undef EVALCODE
|
||||
@@ -214,7 +214,7 @@ uint8_t PaymentsCCpriv[32] = { 0x03, 0xc9, 0x73, 0xc2, 0xb8, 0x30, 0x3d, 0xbd, 0
|
||||
#define FUNCNAME IsGatewaysInput
|
||||
#define EVALCODE EVAL_GATEWAYS
|
||||
const char *GatewaysCCaddr = "RKWpoK6vTRtq5b9qrRBodLkCzeURHeEk33";
|
||||
const char *GatewaysNormaladdr = "RGJKV97ZN1wBfunuMt1tebiiHENNEq73Yh";
|
||||
const char *GatewaysNormaladdr = "RGJKV97ZN1wBfunuMt1tebiiHENNEq73Yh"; // wif UxJFYqEvLAjWPPRvn8NN1fRWscBxQZXZB5BBgc3HiapKVQBYNcmo
|
||||
char GatewaysCChexstr[67] = { "03ea9c062b9652d8eff34879b504eda0717895d27597aaeb60347d65eed96ccb40" };
|
||||
uint8_t GatewaysCCpriv[32] = { 0xf7, 0x4b, 0x5b, 0xa2, 0x7a, 0x5e, 0x9c, 0xda, 0x89, 0xb1, 0xcb, 0xb9, 0xe6, 0x9c, 0x2c, 0x70, 0x85, 0x37, 0xdd, 0x00, 0x7a, 0x67, 0xff, 0x7c, 0x62, 0x1b, 0xe2, 0xfb, 0x04, 0x8f, 0x85, 0xbf };
|
||||
#include "CCcustom.inc"
|
||||
@@ -282,13 +282,13 @@ struct CCcontract_info *CCinit(struct CCcontract_info *cp,uint8_t evalcode)
|
||||
cp->validate = AuctionValidate;
|
||||
cp->ismyvin = IsAuctionInput;
|
||||
break;
|
||||
case EVAL_MOFN:
|
||||
strcpy(cp->unspendableCCaddr,MofNCCaddr);
|
||||
strcpy(cp->normaladdr,MofNNormaladdr);
|
||||
strcpy(cp->CChexstr,MofNCChexstr);
|
||||
memcpy(cp->CCpriv,MofNCCpriv,32);
|
||||
cp->validate = MofNValidate;
|
||||
cp->ismyvin = IsMofNInput;
|
||||
case EVAL_HEIR:
|
||||
strcpy(cp->unspendableCCaddr,HeirCCaddr);
|
||||
strcpy(cp->normaladdr,HeirNormaladdr);
|
||||
strcpy(cp->CChexstr,HeirCChexstr);
|
||||
memcpy(cp->CCpriv,HeirCCpriv,32);
|
||||
cp->validate = HeirValidate;
|
||||
cp->ismyvin = IsHeirInput;
|
||||
break;
|
||||
case EVAL_CHANNELS:
|
||||
strcpy(cp->unspendableCCaddr,ChannelsCCaddr);
|
||||
|
||||
@@ -24,11 +24,12 @@
|
||||
bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx);
|
||||
|
||||
std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds);
|
||||
std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout);
|
||||
std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyvout,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout);
|
||||
double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid);
|
||||
std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks);
|
||||
std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount);
|
||||
UniValue DiceInfo(uint256 diceid);
|
||||
UniValue DiceList();
|
||||
int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -48,12 +48,16 @@ one other technical note is that komodod has the insight-explorer extensions bui
|
||||
#include <univalue.h>
|
||||
#include <exception>
|
||||
#include "../komodo_defs.h"
|
||||
#include "../utlist.h"
|
||||
#include "../uthash.h"
|
||||
|
||||
extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE;
|
||||
extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE;
|
||||
extern uint32_t ASSETCHAINS_CC;
|
||||
extern char ASSETCHAINS_SYMBOL[];
|
||||
extern std::string CCerror;
|
||||
|
||||
#define SMALLVAL 0.000000000000001
|
||||
#define MIN_NOTARIZATION_CONFIRMS 2
|
||||
union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; };
|
||||
typedef union _bits256 bits256;
|
||||
|
||||
@@ -94,8 +98,8 @@ int32_t is_hexstr(char *str,int32_t n);
|
||||
bool myAddtomempool(CTransaction &tx);
|
||||
//uint64_t myGettxout(uint256 hash,int32_t n);
|
||||
bool myIsutxo_spentinmempool(uint256 txid,int32_t vout);
|
||||
bool mytxid_inmempool(uint256 txid);
|
||||
int32_t myIsutxo_spent(uint256 &spenttxid,uint256 txid,int32_t vout);
|
||||
bool mySendrawtransaction(std::string res);
|
||||
int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex);
|
||||
int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp);
|
||||
int32_t iguana_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t *endianedp);
|
||||
@@ -121,10 +125,11 @@ CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv);
|
||||
// CCutils
|
||||
CPubKey buf2pk(uint8_t *buf33);
|
||||
void endiancpy(uint8_t *dest,uint8_t *src,int32_t len);
|
||||
uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv);
|
||||
uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv,int32_t entropyvout,int32_t usevout);
|
||||
CTxOut MakeCC1vout(uint8_t evalcode,CAmount nValue,CPubKey pk);
|
||||
CTxOut MakeCC1of2vout(uint8_t evalcode,CAmount nValue,CPubKey pk,CPubKey pk2);
|
||||
CC *MakeCCcond1(uint8_t evalcode,CPubKey pk);
|
||||
CC *MakeCCcond1of2(uint8_t evalcode,CPubKey pk1,CPubKey pk2);
|
||||
CC* GetCryptoCondition(CScript const& scriptSig);
|
||||
void CCaddr2set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr);
|
||||
void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr);
|
||||
@@ -132,6 +137,7 @@ bool IsCCInput(CScript const& scriptSig);
|
||||
int32_t unstringbits(char *buf,uint64_t bits);
|
||||
uint64_t stringbits(char *str);
|
||||
uint256 revuint256(uint256 txid);
|
||||
bool pubkey2addr(char *destaddr,uint8_t *pubkey33);
|
||||
char *uint256_str(char *dest,uint256 txid);
|
||||
char *pubkey33_str(char *dest,uint8_t *pubkey33);
|
||||
uint256 Parseuint256(char *hexstr);
|
||||
@@ -148,7 +154,7 @@ bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey);
|
||||
std::vector<uint8_t> Mypubkey();
|
||||
bool Myprivkey(uint8_t myprivkey[]);
|
||||
int64_t CCduration(int32_t &numblocks,uint256 txid);
|
||||
|
||||
bool isCCTxNotarizedConfirmed(uint256 txid);
|
||||
// CCtx
|
||||
std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret);
|
||||
void SetCCunspents(std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs,char *coinaddr);
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
|
||||
/*
|
||||
FinalizeCCTx is a very useful function that will properly sign both CC and normal inputs, adds normal change and the opreturn.
|
||||
|
||||
|
||||
This allows the contract transaction functions to create the appropriate vins and vouts and have FinalizeCCTx create a properly signed transaction.
|
||||
|
||||
|
||||
By using -addressindex=1, it allows tracking of all the CC addresses
|
||||
*/
|
||||
|
||||
|
||||
bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey)
|
||||
{
|
||||
#ifdef ENABLE_WALLET
|
||||
@@ -33,9 +33,8 @@ bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScrip
|
||||
UpdateTransaction(mtx,vini,sigdata);
|
||||
return(true);
|
||||
} else fprintf(stderr,"signing error for SignTx vini.%d %.8f\n",vini,(double)utxovalue/COIN);
|
||||
#else
|
||||
return(false);
|
||||
#endif
|
||||
return(false);
|
||||
}
|
||||
|
||||
std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret)
|
||||
@@ -111,7 +110,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran
|
||||
{
|
||||
privkey = myprivkey;
|
||||
cond = mycond;
|
||||
//fprintf(stderr,"my CC addr.(%s)\n",myaddr);
|
||||
|
||||
}
|
||||
else if ( strcmp(destaddr,unspendable) == 0 )
|
||||
{
|
||||
@@ -119,12 +118,14 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran
|
||||
cond = othercond;
|
||||
//fprintf(stderr,"unspendable CC addr.(%s)\n",unspendable);
|
||||
}
|
||||
else if ( strcmp(destaddr,cp->unspendableaddr2) == 0 )
|
||||
else if ( strcmp(destaddr,cp->unspendableaddr2) == 0)
|
||||
{
|
||||
//fprintf(stderr,"matched %s unspendable2!\n",cp->unspendableaddr2);
|
||||
privkey = cp->unspendablepriv2;
|
||||
if ( othercond2 == 0 )
|
||||
if ( othercond2 == 0 && cp->evalcode != EVAL_CHANNELS)
|
||||
othercond2 = MakeCCcond1(cp->evalcode2,cp->unspendablepk2);
|
||||
else if ( othercond2 == 0 && cp->evalcode == EVAL_CHANNELS)
|
||||
othercond2 = MakeCCcond1of2(cp->evalcode2,cp->unspendablepk2,cp->unspendablepk3);
|
||||
cond = othercond2;
|
||||
}
|
||||
else if ( strcmp(destaddr,cp->unspendableaddr3) == 0 )
|
||||
@@ -137,7 +138,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"vini.%d has unknown CC address.(%s)\n",i,destaddr);
|
||||
fprintf(stderr,"CC signing error: vini.%d has unknown CC address.(%s)\n",i,destaddr);
|
||||
continue;
|
||||
}
|
||||
uint256 sighash = SignatureHash(CCPubKey(cond), mtx, i, SIGHASH_ALL, utxovalues[i],consensusBranchId, &txdata);
|
||||
@@ -274,6 +275,11 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *
|
||||
abovei = belowi = -1;
|
||||
for (above=below=i=0; i<numunspents; i++)
|
||||
{
|
||||
// Filter to randomly pick utxo to avoid conflicts, and having multiple CC choose the same ones.
|
||||
//if ( numunspents > 500 ) {
|
||||
// if ( (rand() % 100) < 80 )
|
||||
// continue;
|
||||
//}
|
||||
if ( (atx_value= utxos[i].nValue) <= 0 )
|
||||
continue;
|
||||
if ( atx_value == value )
|
||||
@@ -320,21 +326,26 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *
|
||||
|
||||
int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs)
|
||||
{
|
||||
int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=1024; int64_t above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector<COutput> vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up;
|
||||
int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=64; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector<COutput> vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up;
|
||||
#ifdef ENABLE_WALLET
|
||||
const CKeyStore& keystore = *pwalletMain;
|
||||
assert(pwalletMain != NULL);
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
pwalletMain->AvailableCoins(vecOutputs, false, NULL, true);
|
||||
utxos = (struct CC_utxo *)calloc(maxutxos,sizeof(*utxos));
|
||||
threshold = total/maxinputs;
|
||||
if ( maxinputs > maxutxos )
|
||||
maxutxos = maxinputs;
|
||||
sum = 0;
|
||||
BOOST_FOREACH(const COutput& out, vecOutputs)
|
||||
{
|
||||
if ( out.fSpendable != 0 )
|
||||
if ( out.fSpendable != 0 && out.tx->vout[out.i].nValue >= threshold )
|
||||
{
|
||||
txid = out.tx->GetHash();
|
||||
vout = out.i;
|
||||
if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 )
|
||||
if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 )
|
||||
{
|
||||
//fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout);
|
||||
if ( mtx.vin.size() > 0 )
|
||||
{
|
||||
for (i=0; i<mtx.vin.size(); i++)
|
||||
@@ -357,8 +368,9 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3
|
||||
up->txid = txid;
|
||||
up->nValue = out.tx->vout[out.i].nValue;
|
||||
up->vout = vout;
|
||||
sum += up->nValue;
|
||||
//fprintf(stderr,"add %.8f to vins array.%d of %d\n",(double)up->nValue/COIN,n,maxutxos);
|
||||
if ( n >= maxutxos )
|
||||
if ( n >= maxutxos || sum >= total )
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,6 @@ CTxOut MakeCC1of2vout(uint8_t evalcode,CAmount nValue,CPubKey pk1,CPubKey pk2)
|
||||
CTxOut vout;
|
||||
CC *payoutCond = MakeCCcond1of2(evalcode,pk1,pk2);
|
||||
vout = CTxOut(nValue,CCPubKey(payoutCond));
|
||||
fprintf(stderr,"payoutCond: %s\n",cc_conditionToJSONString(payoutCond));
|
||||
cc_free(payoutCond);
|
||||
return(vout);
|
||||
}
|
||||
@@ -75,6 +74,7 @@ CC* GetCryptoCondition(CScript const& scriptSig)
|
||||
std::vector<unsigned char> ffbin;
|
||||
if (scriptSig.GetOp(pc, opcode, ffbin))
|
||||
return cc_readFulfillmentBinary((uint8_t*)ffbin.data(), ffbin.size()-1);
|
||||
else return(0);
|
||||
}
|
||||
|
||||
bool IsCCInput(CScript const& scriptSig)
|
||||
@@ -194,7 +194,7 @@ bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey)
|
||||
strcpy(destaddr,(char *)CBitcoinAddress(address).ToString().c_str());
|
||||
return(true);
|
||||
}
|
||||
fprintf(stderr,"ExtractDestination failed\n");
|
||||
//fprintf(stderr,"ExtractDestination failed\n");
|
||||
return(false);
|
||||
}
|
||||
|
||||
@@ -386,12 +386,12 @@ int64_t CCduration(int32_t &numblocks,uint256 txid)
|
||||
numblocks = 0;
|
||||
if ( myGetTransaction(txid,tx,hashBlock) == 0 )
|
||||
{
|
||||
fprintf(stderr,"CCduration cant find duration txid %s\n",uint256_str(str,txid));
|
||||
//fprintf(stderr,"CCduration cant find duration txid %s\n",uint256_str(str,txid));
|
||||
return(0);
|
||||
}
|
||||
else if ( hashBlock == zeroid )
|
||||
{
|
||||
fprintf(stderr,"CCduration no hashBlock for txid %s\n",uint256_str(str,txid));
|
||||
//fprintf(stderr,"CCduration no hashBlock for txid %s\n",uint256_str(str,txid));
|
||||
return(0);
|
||||
}
|
||||
else if ( (pindex= mapBlockIndex[hashBlock]) == 0 || (txtime= pindex->nTime) == 0 || (txheight= pindex->nHeight) <= 0 )
|
||||
@@ -401,12 +401,22 @@ int64_t CCduration(int32_t &numblocks,uint256 txid)
|
||||
}
|
||||
else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime || pindex->nHeight <= txheight )
|
||||
{
|
||||
fprintf(stderr,"CCduration backwards timestamps %u %u for txid %s hts.(%d %d)\n",(uint32_t)pindex->nTime,txtime,uint256_str(str,txid),txheight,(int32_t)pindex->nHeight);
|
||||
if ( pindex->nTime < txtime )
|
||||
fprintf(stderr,"CCduration backwards timestamps %u %u for txid %s hts.(%d %d)\n",(uint32_t)pindex->nTime,txtime,uint256_str(str,txid),txheight,(int32_t)pindex->nHeight);
|
||||
return(0);
|
||||
}
|
||||
numblocks = (pindex->nHeight - txheight);
|
||||
duration = (pindex->nTime - txtime);
|
||||
fprintf(stderr,"duration %d (%u - %u) numblocks %d (%d - %d)\n",(int32_t)duration,(uint32_t)pindex->nTime,txtime,numblocks,pindex->nHeight,txheight);
|
||||
//fprintf(stderr,"duration %d (%u - %u) numblocks %d (%d - %d)\n",(int32_t)duration,(uint32_t)pindex->nTime,txtime,numblocks,pindex->nHeight,txheight);
|
||||
return(duration);
|
||||
}
|
||||
|
||||
bool isCCTxNotarizedConfirmed(uint256 txid)
|
||||
{
|
||||
int32_t confirms;
|
||||
|
||||
CCduration(confirms,txid);
|
||||
if (confirms >= MIN_NOTARIZATION_CONFIRMS)
|
||||
return (true);
|
||||
return (false);
|
||||
}
|
||||
|
||||
@@ -249,8 +249,8 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx
|
||||
}
|
||||
fprintf(stderr,"fillbuy validated\n");
|
||||
break;
|
||||
case 'e': // selloffer
|
||||
break; // disable swaps
|
||||
//case 'e': // selloffer
|
||||
// break; // disable swaps
|
||||
case 's': // selloffer
|
||||
//vin.0: normal input
|
||||
//vin.1+: valid CC output for sale
|
||||
@@ -322,6 +322,7 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx
|
||||
fprintf(stderr,"fill validated\n");
|
||||
break;
|
||||
case 'E': // fillexchange
|
||||
return eval->Invalid("unexpected assets fillexchange funcid");
|
||||
break; // disable asset swaps
|
||||
//vin.0: normal input
|
||||
//vin.1: unspendable.(vout.0 assetoshis from selloffer) sellTx.vout[0]
|
||||
@@ -371,6 +372,10 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx
|
||||
}
|
||||
fprintf(stderr,"fill validated\n");
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"illegal assets funcid.(%c)\n",funcid);
|
||||
return eval->Invalid("unexpected assets funcid");
|
||||
break;
|
||||
}
|
||||
return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts));
|
||||
}
|
||||
|
||||
@@ -120,6 +120,7 @@ bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t
|
||||
|
||||
int64_t AddAuctionInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs)
|
||||
{
|
||||
// add threshold check
|
||||
char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector<uint8_t> origpubkey; CTransaction vintx; int32_t n = 0;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
GetCCaddress(cp,coinaddr,pk);
|
||||
|
||||
@@ -62,46 +62,86 @@ Possible third iteration:
|
||||
|
||||
// start of consensus code
|
||||
|
||||
int64_t IsChannelsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v)
|
||||
int64_t IsChannelsvout(struct CCcontract_info *cp,const CTransaction& tx,CPubKey srcpub, CPubKey destpub,int32_t v)
|
||||
{
|
||||
char destaddr[64];
|
||||
char destaddr[65],channeladdr[65];
|
||||
|
||||
GetCCaddress1of2(cp,channeladdr,srcpub,destpub);
|
||||
if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 )
|
||||
{
|
||||
if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,cp->unspendableCCaddr) == 0 )
|
||||
if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,channeladdr) == 0 )
|
||||
return(tx.vout[v].nValue);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
int64_t IsChannelsMarkervout(struct CCcontract_info *cp,const CTransaction& tx,CPubKey srcpub,int32_t v)
|
||||
{
|
||||
char destaddr[65],ccaddr[65];
|
||||
|
||||
GetCCaddress(cp,ccaddr,srcpub);
|
||||
if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 )
|
||||
{
|
||||
if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,ccaddr) == 0 )
|
||||
return(tx.vout[v].nValue);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
CScript EncodeChannelsOpRet(uint8_t funcid,uint256 opentxid,CPubKey srcpub,CPubKey destpub,int32_t numpayments,int64_t payment,uint256 hashchain)
|
||||
{
|
||||
CScript opret; uint8_t evalcode = EVAL_CHANNELS;
|
||||
opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << opentxid << srcpub << destpub << numpayments << payment << hashchain);
|
||||
return(opret);
|
||||
}
|
||||
|
||||
uint8_t DecodeChannelsOpRet(const CScript &scriptPubKey,uint256 &opentxid, CPubKey &srcpub,CPubKey &destpub,int32_t &numpayments,int64_t &payment,uint256 &hashchain)
|
||||
{
|
||||
std::vector<uint8_t> vopret; uint8_t *script,e,f;
|
||||
GetOpReturnData(scriptPubKey, vopret);
|
||||
if ( vopret.size() > 2 )
|
||||
{
|
||||
script = (uint8_t *)vopret.data();
|
||||
if ( script[0] == EVAL_CHANNELS )
|
||||
{
|
||||
if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> opentxid; ss >> srcpub; ss >> destpub; ss >> numpayments; ss >> payment; ss >> hashchain) != 0 )
|
||||
{
|
||||
return(f);
|
||||
}
|
||||
} else fprintf(stderr,"script[0] %02x != EVAL_CHANNELS\n",script[0]);
|
||||
} else fprintf(stderr,"not enough opret.[%d]\n",(int32_t)vopret.size());
|
||||
return(0);
|
||||
}
|
||||
|
||||
bool ChannelsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee)
|
||||
{
|
||||
static uint256 zerohash;
|
||||
CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis;
|
||||
uint256 txid,param3;
|
||||
CPubKey srcpub,destpub;
|
||||
int32_t param1; int64_t param2; uint8_t funcid;
|
||||
CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis;
|
||||
numvins = tx.vin.size();
|
||||
numvouts = tx.vout.size();
|
||||
for (i=0; i<numvins; i++)
|
||||
|
||||
if ((numvouts=tx.vout.size()) > 0 && DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3)!=0)
|
||||
{
|
||||
//fprintf(stderr,"vini.%d\n",i);
|
||||
if ( (*cp->ismyvin)(tx.vin[i].scriptSig) != 0 )
|
||||
for (i=0; i<numvins; i++)
|
||||
{
|
||||
//fprintf(stderr,"vini.%d check mempool\n",i);
|
||||
if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 )
|
||||
return eval->Invalid("cant find vinTx");
|
||||
else
|
||||
{
|
||||
//fprintf(stderr,"vini.%d check hash and vout\n",i);
|
||||
if ( hashBlock == zerohash )
|
||||
return eval->Invalid("cant Channels from mempool");
|
||||
if ( (assetoshis= IsChannelsvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 )
|
||||
inputs += assetoshis;
|
||||
inputs += vinTx.vout[tx.vin[i].prevout.n].nValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return eval->Invalid("invalid op_return data");
|
||||
}
|
||||
for (i=0; i<numvouts; i++)
|
||||
{
|
||||
//fprintf(stderr,"i.%d of numvouts.%d\n",i,numvouts);
|
||||
if ( (assetoshis= IsChannelsvout(cp,tx,i)) != 0 )
|
||||
outputs += assetoshis;
|
||||
outputs += tx.vout[i].nValue;
|
||||
}
|
||||
if ( inputs != outputs+txfee )
|
||||
{
|
||||
@@ -113,9 +153,13 @@ bool ChannelsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti
|
||||
|
||||
bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx)
|
||||
{
|
||||
int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64];
|
||||
return(false);
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > txids;
|
||||
int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numpayments,p1,param1; bool retval;
|
||||
uint256 txid,hashblock,p3,param3,opentxid,tmp_txid,genhashchain,hashchain;
|
||||
uint8_t funcid,hash[32],hashdest[32];
|
||||
int64_t p2,param2,payment;
|
||||
CPubKey srcpub, destpub;
|
||||
CTransaction channelOpenTx,channelCloseTx,prevTx;
|
||||
|
||||
numvins = tx.vin.size();
|
||||
numvouts = tx.vout.size();
|
||||
preventCCvins = preventCCvouts = -1;
|
||||
@@ -123,15 +167,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &
|
||||
return eval->Invalid("no vouts");
|
||||
else
|
||||
{
|
||||
for (i=0; i<numvins; i++)
|
||||
{
|
||||
if ( IsCCInput(tx.vin[0].scriptSig) == 0 )
|
||||
{
|
||||
return eval->Invalid("illegal normal vini");
|
||||
}
|
||||
}
|
||||
//fprintf(stderr,"check amounts\n");
|
||||
if ( ChannelsExactAmounts(cp,eval,tx,1,10000) == false )
|
||||
if (ChannelsExactAmounts(cp,eval,tx,1,10000) == false )
|
||||
{
|
||||
fprintf(stderr,"Channelsget invalid amount\n");
|
||||
return false;
|
||||
@@ -140,10 +176,188 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &
|
||||
{
|
||||
txid = tx.GetHash();
|
||||
memcpy(hash,&txid,sizeof(hash));
|
||||
|
||||
if ( (funcid = DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey, opentxid, srcpub, destpub, param1, param2, param3)) != 0)
|
||||
{
|
||||
switch ( funcid )
|
||||
{
|
||||
case 'O':
|
||||
//vin.0: normal input
|
||||
//vout.0: CC vout for channel funding on CC1of2 pubkey
|
||||
//vout.1: CC vout marker to senders pubKey
|
||||
//vout.2: CC vout marker to receiver pubkey
|
||||
//vout.n-2: normal change
|
||||
//vout.n-1: opreturn - 'O' zerotxid senderspubkey receiverspubkey totalnumberofpayments paymentamount hashchain
|
||||
return eval->Invalid("unexpected ChannelsValidate for channelsopen!");
|
||||
case 'P':
|
||||
//vin.0: normal input
|
||||
//vin.1: CC input from channel funding
|
||||
//vin.2: CC input from src marker
|
||||
//vout.0: CC vout change to CC1of2 pubkey
|
||||
//vout.1: CC vout marker to senders pubKey
|
||||
//vout.2: CC vout marker to receiver pubkey
|
||||
//vout.3: normal output of payment amount to receiver pubkey
|
||||
//vout.n-2: normal change
|
||||
//vout.n-1: opreturn - 'P' opentxid senderspubkey receiverspubkey depth numpayments secret
|
||||
if (isCCTxNotarizedConfirmed(opentxid) == 0)
|
||||
return eval->Invalid("channelOpen is not yet confirmed(notarised)!");
|
||||
else if ( IsCCInput(tx.vin[0].scriptSig) != 0 )
|
||||
return eval->Invalid("vin.0 is normal for channelPayment!");
|
||||
else if ( IsCCInput(tx.vin[1].scriptSig) == 0 )
|
||||
return eval->Invalid("vin.1 is CC for channelPayment!");
|
||||
else if ( IsCCInput(tx.vin[2].scriptSig) == 0 )
|
||||
return eval->Invalid("vin.2 is CC for channelPayment!");
|
||||
else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 )
|
||||
return eval->Invalid("vout.0 is CC for channelPayment!");
|
||||
else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 )
|
||||
return eval->Invalid("vout.1 is CC for channelPayment (marker to srcPub)!");
|
||||
else if ( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() == 0 )
|
||||
return eval->Invalid("vout.2 is CC for channelPayment (marker to dstPub)!");
|
||||
else if ( tx.vout[3].scriptPubKey.IsPayToCryptoCondition() != 0 )
|
||||
return eval->Invalid("vout.3 is normal for channelPayment!");
|
||||
else if ( tx.vout[3].scriptPubKey!=CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG)
|
||||
return eval->Invalid("payment funds do not go to receiver!");
|
||||
else if ( param1 > CHANNELS_MAXPAYMENTS)
|
||||
return eval->Invalid("too many payment increments!");
|
||||
else
|
||||
{
|
||||
if (myGetTransaction(opentxid,channelOpenTx,hashblock) != 0)
|
||||
{
|
||||
if ((numvouts=channelOpenTx.vout.size()) > 0 && (funcid=DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain)) != 0 && funcid!='O')
|
||||
return eval->Invalid("invalid channelopen OP_RETURN data!");
|
||||
endiancpy(hash, (uint8_t * ) & param3, 32);
|
||||
for (i = 0; i < numpayments-param1; i++)
|
||||
{
|
||||
vcalc_sha256(0, hashdest, hash, 32);
|
||||
memcpy(hash, hashdest, 32);
|
||||
}
|
||||
endiancpy((uint8_t*)&genhashchain,hashdest,32);
|
||||
if (hashchain!=genhashchain)
|
||||
return eval->Invalid("invalid secret for payment, does not reach final hashchain!");
|
||||
else if (tx.vout[3].nValue != param2*payment)
|
||||
return eval->Invalid("vout amount does not match number_of_payments*payment!");
|
||||
}
|
||||
if (myGetTransaction(tx.vin[1].prevout.hash,prevTx,hashblock) != 0)
|
||||
{
|
||||
if ((numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, p1, p2, p3) == 0)
|
||||
return eval->Invalid("invalid previous tx OP_RETURN data!");
|
||||
else if (tx.vout[1].scriptPubKey != prevTx.vout[1].scriptPubKey)
|
||||
return eval->Invalid("invalid destination for sender marker!");
|
||||
else if (tx.vout[2].scriptPubKey != prevTx.vout[2].scriptPubKey)
|
||||
return eval->Invalid("invalid destination for receiver marker!");
|
||||
else if (param1+param2!=p1)
|
||||
return eval->Invalid("invalid payment depth!");
|
||||
else if (tx.vout[3].nValue > prevTx.vout[0].nValue)
|
||||
return eval->Invalid("not enough funds in channel for that amount!");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'C':
|
||||
//vin.0: normal input
|
||||
//vin.1: CC input from channel funding
|
||||
//vin.2: CC input from src marker
|
||||
//vout.0: CC vout for channel funding
|
||||
//vout.1: CC vout marker to senders pubKey
|
||||
//vout.2: CC vout marker to receiver pubkey
|
||||
//vout.n-2: normal change
|
||||
//vout.n-1: opreturn - 'C' opentxid senderspubkey receiverspubkey 0 0 0
|
||||
if (isCCTxNotarizedConfirmed(opentxid) == 0)
|
||||
return eval->Invalid("channelOpen is not yet confirmed(notarised)!");
|
||||
else if ( IsCCInput(tx.vin[0].scriptSig) != 0 )
|
||||
return eval->Invalid("vin.0 is normal for channelClose!");
|
||||
else if ( IsCCInput(tx.vin[1].scriptSig) == 0 )
|
||||
return eval->Invalid("vin.1 is CC for channelClose!");
|
||||
else if ( IsCCInput(tx.vin[2].scriptSig) == 0 )
|
||||
return eval->Invalid("vin.2 is CC for channelClose!");
|
||||
else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 )
|
||||
return eval->Invalid("vout.0 is CC for channelClose!");
|
||||
else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 )
|
||||
return eval->Invalid("vout.1 is CC for channelClose (marker to srcPub)!");
|
||||
else if ( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() == 0 )
|
||||
return eval->Invalid("vout.2 is CC for channelClose (marker to dstPub)!");
|
||||
else if ( param1 > CHANNELS_MAXPAYMENTS)
|
||||
return eval->Invalid("too many payment increments!");
|
||||
else if (myGetTransaction(opentxid,channelOpenTx,hashblock) == 0)
|
||||
return eval->Invalid("invalid open txid!");
|
||||
else if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain) != 'O')
|
||||
return eval->Invalid("invalid channelopen OP_RETURN data!");
|
||||
else if (tx.vout[0].nValue != param1*payment)
|
||||
return eval->Invalid("vout amount does not match number_of_payments*payment!");
|
||||
else if (myGetTransaction(tx.vin[1].prevout.hash,prevTx,hashblock) != 0)
|
||||
{
|
||||
if ((numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, p1, p2, p3) == 0)
|
||||
return eval->Invalid("invalid previous tx OP_RETURN data!");
|
||||
else if (tx.vout[1].scriptPubKey != prevTx.vout[1].scriptPubKey)
|
||||
return eval->Invalid("invalid destination for sender marker!");
|
||||
else if (tx.vout[2].scriptPubKey != prevTx.vout[2].scriptPubKey)
|
||||
return eval->Invalid("invalid destination for receiver marker!");
|
||||
else if (tx.vout[0].nValue != prevTx.vout[0].nValue)
|
||||
return eval->Invalid("invalid CC amount, amount must match funds in channel");
|
||||
}
|
||||
break;
|
||||
case 'R':
|
||||
//vin.0: normal input
|
||||
//vin.1: CC input from channel funding
|
||||
//vin.2: CC input from src marker
|
||||
//vout.0: CC vout marker to senders pubKey
|
||||
//vout.1: CC vout marker to receiver pubKey
|
||||
//vout.2: normal output of CC input to senders pubkey
|
||||
//vout.n-2: normal change
|
||||
//vout.n-1: opreturn - 'R' opentxid senderspubkey receiverspubkey numpayments payment closetxid
|
||||
if (isCCTxNotarizedConfirmed(opentxid) == 0)
|
||||
return eval->Invalid("channelOpen is not yet confirmed(notarised)!");
|
||||
else if (isCCTxNotarizedConfirmed(param3) == 0)
|
||||
return eval->Invalid("channelClose is not yet confirmed(notarised)!");
|
||||
else if ( IsCCInput(tx.vin[0].scriptSig) != 0 )
|
||||
return eval->Invalid("vin.0 is normal for channelRefund!");
|
||||
else if ( IsCCInput(tx.vin[1].scriptSig) == 0 )
|
||||
return eval->Invalid("vin.1 is CC for channelRefund!");
|
||||
else if ( IsCCInput(tx.vin[2].scriptSig) == 0 )
|
||||
return eval->Invalid("vin.2 is CC for channelRefund!");
|
||||
else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 )
|
||||
return eval->Invalid("vout.0 is CC for channelRefund (marker to srcPub)!");
|
||||
else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 )
|
||||
return eval->Invalid("vout.1 is CC for channelRefund (marker to dstPub)!");
|
||||
else if ( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 )
|
||||
return eval->Invalid("vout.2 is normal for channelRefund!");
|
||||
else if ( tx.vout[2].scriptPubKey!=CScript() << ParseHex(HexStr(srcpub)) << OP_CHECKSIG)
|
||||
return eval->Invalid("payment funds do not go to sender!");
|
||||
else if ( param1 > CHANNELS_MAXPAYMENTS)
|
||||
return eval->Invalid("too many payment increments!");
|
||||
else if (myGetTransaction(opentxid,channelOpenTx,hashblock) == 0)
|
||||
return eval->Invalid("invalid open txid!");
|
||||
else if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain) != 'O')
|
||||
return eval->Invalid("invalid channelopen OP_RETURN data!");
|
||||
else if (myGetTransaction(param3,channelCloseTx,hashblock) == 0)
|
||||
return eval->Invalid("invalid close txid!");
|
||||
else if ((numvouts=channelCloseTx.vout.size()) > 0 && DecodeChannelsOpRet(channelCloseTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, param1, param2, param3) != 'C')
|
||||
return eval->Invalid("invalid channelclose OP_RETURN data!");
|
||||
else if (tmp_txid!=opentxid)
|
||||
return eval->Invalid("invalid close tx, opentxid do not match on close and refund!");
|
||||
else if (tx.vout[2].nValue != param1*payment)
|
||||
return eval->Invalid("vout amount does not match number_of_payments*payment!");
|
||||
else if (myGetTransaction(tx.vin[1].prevout.hash,prevTx,hashblock) != 0)
|
||||
{
|
||||
if ((numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, p1, p2, p3) == 0)
|
||||
return eval->Invalid("invalid previous tx OP_RETURN data!");
|
||||
else if (tx.vout[0].scriptPubKey != prevTx.vout[1].scriptPubKey)
|
||||
return eval->Invalid("invalid destination for sender marker!");
|
||||
else if (tx.vout[1].scriptPubKey != prevTx.vout[2].scriptPubKey)
|
||||
return eval->Invalid("invalid destination for receiver marker!");
|
||||
else if (tx.vout[2].nValue != prevTx.vout[0].nValue)
|
||||
return eval->Invalid("invalid amount, refund amount and funds in channel must match!");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"illegal channels funcid.(%c)\n",funcid);
|
||||
return eval->Invalid("unexpected channels funcid");
|
||||
break;
|
||||
}
|
||||
} else return eval->Invalid("unexpected channels missing funcid");
|
||||
retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts);
|
||||
if ( retval != 0 )
|
||||
fprintf(stderr,"Channelsget validated\n");
|
||||
else fprintf(stderr,"Channelsget invalid\n");
|
||||
fprintf(stderr,"Channel tx validated\n");
|
||||
else fprintf(stderr,"Channel tx invalid\n");
|
||||
return(retval);
|
||||
}
|
||||
}
|
||||
@@ -152,65 +366,76 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &
|
||||
|
||||
// helper functions for rpc calls in rpcwallet.cpp
|
||||
|
||||
CScript EncodeChannelsOpRet(uint8_t funcid,CPubKey srcpub,CPubKey destpub,int32_t numpayments,int64_t payment,uint256 hashchain)
|
||||
int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, CTransaction openTx, uint256 &prevtxid)
|
||||
{
|
||||
CScript opret; uint8_t evalcode = EVAL_CHANNELS;
|
||||
opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << srcpub << destpub << numpayments << payment << hashchain);
|
||||
return(opret);
|
||||
}
|
||||
|
||||
uint8_t DecodeChannelsOpRet(uint256 txid,const CScript &scriptPubKey,CPubKey &srcpub,CPubKey &destpub,int32_t &numpayments,int64_t &payment,uint256 &hashchain)
|
||||
{
|
||||
std::vector<uint8_t> vopret; uint8_t *script,e,f,funcid;
|
||||
GetOpReturnData(scriptPubKey, vopret);
|
||||
if ( vopret.size() > 2 )
|
||||
{
|
||||
script = (uint8_t *)vopret.data();
|
||||
if ( script[0] == EVAL_CHANNELS )
|
||||
{
|
||||
if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> srcpub; ss >> destpub; ss >> numpayments; ss >> payment; ss >> hashchain) != 0 )
|
||||
{
|
||||
return(f);
|
||||
}
|
||||
} else fprintf(stderr,"script[0] %02x != EVAL_CHANNELS\n",script[0]);
|
||||
} else fprintf(stderr,"not enough opret.[%d]\n",(int32_t)vopret.size());
|
||||
return(0);
|
||||
}
|
||||
|
||||
int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs)
|
||||
{
|
||||
char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector<uint8_t> origpubkey; CTransaction vintx; int32_t vout,n = 0;
|
||||
char coinaddr[65]; int64_t param2,totalinputs = 0,numvouts; uint256 txid=zeroid,tmp_txid,hashBlock,param3; CTransaction tx; int32_t param1;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
GetCCaddress(cp,coinaddr,pk);
|
||||
SetCCunspents(unspentOutputs,coinaddr);
|
||||
CPubKey srcpub,destpub;
|
||||
uint8_t myprivkey[32];
|
||||
|
||||
if ((numvouts=openTx.vout.size()) > 0 && DecodeChannelsOpRet(openTx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)=='O')
|
||||
{
|
||||
GetCCaddress1of2(cp,coinaddr,srcpub,destpub);
|
||||
SetCCunspents(unspentOutputs,coinaddr);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"invalid channel open txid\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
vout = (int32_t)it->first.index;
|
||||
// no need to prevent dup
|
||||
if ( GetTransaction(txid,vintx,hashBlock,false) != 0 )
|
||||
if ( (int32_t)it->first.index==0 && GetTransaction(it->first.txhash,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0)
|
||||
{
|
||||
if ( (nValue= IsChannelsvout(cp,vintx,vout)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 )
|
||||
if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 &&
|
||||
(tmp_txid==openTx.GetHash() || tx.GetHash()==openTx.GetHash()) &&
|
||||
(totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0)+IsChannelsMarkervout(cp,tx,srcpub,1))>0)
|
||||
{
|
||||
if ( total != 0 && maxinputs != 0 )
|
||||
mtx.vin.push_back(CTxIn(txid,vout,CScript()));
|
||||
nValue = it->second.satoshis;
|
||||
totalinputs += nValue;
|
||||
n++;
|
||||
if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) )
|
||||
break;
|
||||
txid = it->first.txhash;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(totalinputs);
|
||||
if (txid!=zeroid && myIsutxo_spentinmempool(txid,0) != 0)
|
||||
{
|
||||
txid=zeroid;
|
||||
int32_t mindepth=CHANNELS_MAXPAYMENTS;
|
||||
BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx)
|
||||
{
|
||||
const CTransaction &txmempool = e.GetTx();
|
||||
const uint256 &hash = txmempool.GetHash();
|
||||
|
||||
if ((numvouts=txmempool.vout.size()) > 0 && DecodeChannelsOpRet(txmempool.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3) != 0 &&
|
||||
tmp_txid==openTx.GetHash() && param1 < mindepth)
|
||||
{
|
||||
txid=hash;
|
||||
totalinputs=txmempool.vout[0].nValue+txmempool.vout[1].nValue;
|
||||
mindepth=param1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (txid != zeroid)
|
||||
{
|
||||
prevtxid=txid;
|
||||
mtx.vin.push_back(CTxIn(txid,0,CScript()));
|
||||
mtx.vin.push_back(CTxIn(txid,1,CScript()));
|
||||
Myprivkey(myprivkey);
|
||||
CCaddr2set(cp,EVAL_CHANNELS,srcpub,myprivkey,coinaddr);
|
||||
CCaddr3set(cp,EVAL_CHANNELS,destpub,myprivkey,coinaddr);
|
||||
return totalinputs;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment)
|
||||
{
|
||||
CMutableTransaction mtx; uint8_t hash[32],hashdest[32]; uint64_t funds; int32_t i; uint256 hashchain,entropy,hentropy; CPubKey mypk; struct CCcontract_info *cp,C;
|
||||
CMutableTransaction mtx; uint8_t hash[32],hashdest[32]; uint64_t funds; int32_t i; uint256 hashchain,entropy,hentropy;
|
||||
CPubKey mypk; struct CCcontract_info *cp,C;
|
||||
|
||||
if ( numpayments <= 0 || payment <= 0 || numpayments > CHANNELS_MAXPAYMENTS )
|
||||
{
|
||||
CCerror = strprintf("invalid ChannelsFund param numpayments.%d max.%d payment.%lld\n",numpayments,CHANNELS_MAXPAYMENTS,(long long)payment);
|
||||
CCerror = strprintf("invalid ChannelOpen param numpayments.%d max.%d payment.%lld\n",numpayments,CHANNELS_MAXPAYMENTS,(long long)payment);
|
||||
fprintf(stderr,"%s\n",CCerror.c_str());
|
||||
return("");
|
||||
}
|
||||
@@ -221,7 +446,7 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64
|
||||
funds = numpayments * payment;
|
||||
if ( AddNormalinputs(mtx,mypk,funds+3*txfee,64) > 0 )
|
||||
{
|
||||
hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash);
|
||||
hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n,1);
|
||||
endiancpy(hash,(uint8_t *)&hentropy,32);
|
||||
for (i=0; i<numpayments; i++)
|
||||
{
|
||||
@@ -232,106 +457,319 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64
|
||||
mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS,funds,mypk,destpub));
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk));
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub));
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('O',mypk,destpub,numpayments,payment,hashchain)));
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('O',zeroid,mypk,destpub,numpayments,payment,hashchain)));
|
||||
}
|
||||
return("");
|
||||
}
|
||||
|
||||
std::string ChannelStop(uint64_t txfee,CPubKey destpub,uint256 origtxid)
|
||||
std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint256 secret)
|
||||
{
|
||||
CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C;
|
||||
CMutableTransaction mtx; CPubKey mypk,srcpub,destpub; uint256 txid,hashchain,gensecret,hashblock,entropy,hentropy,prevtxid,param3;
|
||||
struct CCcontract_info *cp,C; int32_t i,funcid,prevdepth,numvouts,numpayments,totalnumpayments;
|
||||
int64_t payment,change,funds,param2;
|
||||
uint8_t hash[32],hashdest[32];
|
||||
CTransaction channelOpenTx,prevTx;
|
||||
|
||||
cp = CCinit(&C,EVAL_CHANNELS);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
if (GetTransaction(opentxid,channelOpenTx,hashblock,false) == 0)
|
||||
{
|
||||
fprintf(stderr, "invalid channel open txid\n");
|
||||
return ("");
|
||||
}
|
||||
if (AddNormalinputs(mtx,mypk,2*txfee,1) > 0)
|
||||
{
|
||||
if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && (change=funds-amount-txfee)>=0)
|
||||
{
|
||||
if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, totalnumpayments, payment, hashchain)=='O')
|
||||
{
|
||||
if (mypk != srcpub && mypk != destpub)
|
||||
{
|
||||
fprintf(stderr,"this is not our channel\n");
|
||||
return("");
|
||||
}
|
||||
else if (amount % payment != 0 || amount<payment)
|
||||
{
|
||||
fprintf(stderr,"invalid amount, not a magnitude of payment size\n");
|
||||
return ("");
|
||||
}
|
||||
numpayments=amount/payment;
|
||||
if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0 && (numvouts=prevTx.vout.size()) > 0 &&
|
||||
((funcid = DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, prevdepth, param2, param3)) != 0) &&
|
||||
(funcid == 'P' || funcid=='O'))
|
||||
{
|
||||
if (numpayments > prevdepth)
|
||||
{
|
||||
fprintf(stderr,"not enough funds in channel for that amount\n");
|
||||
return ("");
|
||||
} else if (numpayments == 0)
|
||||
{
|
||||
fprintf(stderr,"invalid amount\n");
|
||||
return ("");
|
||||
}
|
||||
if (secret!=zeroid)
|
||||
{
|
||||
endiancpy(hash, (uint8_t * ) & secret, 32);
|
||||
for (i = 0; i < totalnumpayments-(prevdepth-numpayments); i++)
|
||||
{
|
||||
vcalc_sha256(0, hashdest, hash, 32);
|
||||
memcpy(hash, hashdest, 32);
|
||||
}
|
||||
endiancpy((uint8_t * ) & gensecret, hashdest, 32);
|
||||
if (gensecret!=hashchain)
|
||||
{
|
||||
fprintf(stderr,"invalid secret supplied\n");
|
||||
return("");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hentropy = DiceHashEntropy(entropy,channelOpenTx.vin[0].prevout.hash,channelOpenTx.vin[0].prevout.n,1);
|
||||
if (prevdepth-numpayments)
|
||||
{
|
||||
endiancpy(hash, (uint8_t * ) & hentropy, 32);
|
||||
for (i = 0; i < prevdepth-numpayments; i++)
|
||||
{
|
||||
vcalc_sha256(0, hashdest, hash, 32);
|
||||
memcpy(hash, hashdest, 32);
|
||||
}
|
||||
endiancpy((uint8_t * ) & secret, hashdest, 32);
|
||||
}
|
||||
else endiancpy((uint8_t * ) & secret, (uint8_t * ) & hentropy, 32);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"invalid previous tx\n");
|
||||
return("");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "invalid channel open tx\n");
|
||||
return ("");
|
||||
}
|
||||
mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, change, mypk, destpub));
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk));
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub));
|
||||
mtx.vout.push_back(CTxOut(amount, CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG));
|
||||
return (FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeChannelsOpRet('P', opentxid, mypk, destpub, prevdepth-numpayments, numpayments, secret)));
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"error adding CC inputs\n");
|
||||
return("");
|
||||
}
|
||||
}
|
||||
fprintf(stderr,"error adding normal inputs\n");
|
||||
return("");
|
||||
}
|
||||
|
||||
std::string ChannelClose(uint64_t txfee,uint256 opentxid)
|
||||
{
|
||||
CMutableTransaction mtx; CPubKey mypk,srcpub,destpub; struct CCcontract_info *cp,C;
|
||||
CTransaction channelOpenTx;
|
||||
uint256 hashblock,tmp_txid,prevtxid,hashchain;
|
||||
int32_t numvouts,numpayments;
|
||||
int64_t payment,funds;
|
||||
|
||||
// verify this is one of our outbound channels
|
||||
cp = CCinit(&C,EVAL_CHANNELS);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
if (GetTransaction(opentxid,channelOpenTx,hashblock,false) == 0)
|
||||
{
|
||||
fprintf(stderr, "invalid channel open txid\n");
|
||||
return ("");
|
||||
}
|
||||
if ((numvouts=channelOpenTx.vout.size()) < 1 || DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,numpayments,payment,hashchain)!='O')
|
||||
{
|
||||
fprintf(stderr, "invalid channel open tx\n");
|
||||
return ("");
|
||||
}
|
||||
if (mypk != srcpub)
|
||||
{
|
||||
fprintf(stderr,"cannot close, you are not channel owner\n");
|
||||
return("");
|
||||
}
|
||||
if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 )
|
||||
{
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk));
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('S',mypk,destpub,0,0,zeroid)));
|
||||
if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && funds-txfee>0)
|
||||
{
|
||||
mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, funds-txfee, mypk, destpub));
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk));
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub));
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('C',opentxid,mypk,destpub,funds/payment,payment,zeroid)));
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"error adding CC inputs\n");
|
||||
return("");
|
||||
}
|
||||
}
|
||||
fprintf(stderr,"error adding normal inputs\n");
|
||||
return("");
|
||||
}
|
||||
|
||||
std::string ChannelPayment(uint64_t txfee,uint256 prevtxid,uint256 origtxid,int32_t n,int64_t amount)
|
||||
std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid)
|
||||
{
|
||||
CMutableTransaction mtx; CPubKey mypk,destpub; uint256 secret; struct CCcontract_info *cp,C; int32_t prevdepth;
|
||||
// verify lasttxid and origtxid match and src is me
|
||||
// also verify hashchain depth and amount, set prevdepth
|
||||
cp = CCinit(&C,EVAL_CHANNELS);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 )
|
||||
{
|
||||
// add locked funds inputs
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk));
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('P',mypk,destpub,prevdepth-n,amount,secret)));
|
||||
}
|
||||
return("");
|
||||
}
|
||||
CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; int64_t funds,payment,param2;
|
||||
int32_t i,numpayments,numvouts,param1;
|
||||
uint256 hashchain,hashblock,txid,prevtxid,param3,entropy,hentropy,secret;
|
||||
CTransaction channelOpenTx,channelCloseTx,prevTx;
|
||||
CPubKey srcpub,destpub;
|
||||
uint8_t funcid,hash[32],hashdest[32];;
|
||||
|
||||
std::string ChannelCollect(uint64_t txfee,uint256 paytxid,uint256 origtxid,int32_t n,int64_t amount)
|
||||
{
|
||||
CMutableTransaction mtx; CPubKey mypk,senderpub; struct CCcontract_info *cp,C; int32_t prevdepth;
|
||||
// verify paytxid and origtxid match and dest is me
|
||||
// also verify hashchain depth and amount
|
||||
cp = CCinit(&C,EVAL_CHANNELS);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 )
|
||||
{
|
||||
// add locked funds inputs
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk));
|
||||
mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('C',senderpub,mypk,prevdepth-n,amount,paytxid)));
|
||||
}
|
||||
return("");
|
||||
}
|
||||
|
||||
std::string ChannelRefund(uint64_t txfee,uint256 stoptxid,uint256 origtxid)
|
||||
{
|
||||
CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; int64_t amount;
|
||||
// verify stoptxid and origtxid match and are mine
|
||||
cp = CCinit(&C,EVAL_CHANNELS);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
if (GetTransaction(closetxid,channelCloseTx,hashblock,false) == 0)
|
||||
{
|
||||
fprintf(stderr, "invalid channel close txid\n");
|
||||
return ("");
|
||||
}
|
||||
if ((numvouts=channelCloseTx.vout.size()) < 1 || DecodeChannelsOpRet(channelCloseTx.vout[numvouts-1].scriptPubKey,txid,srcpub,destpub,param1,param2,param3)!='C')
|
||||
{
|
||||
fprintf(stderr, "invalid channel close tx\n");
|
||||
return ("");
|
||||
}
|
||||
if (txid!=opentxid)
|
||||
{
|
||||
fprintf(stderr, "open and close txid are not from same channel\n");
|
||||
return ("");
|
||||
}
|
||||
if (GetTransaction(opentxid,channelOpenTx,hashblock,false) == 0)
|
||||
{
|
||||
fprintf(stderr, "invalid channel open txid\n");
|
||||
return ("");
|
||||
}
|
||||
if ((numvouts=channelOpenTx.vout.size()) < 1 || DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,txid,srcpub,destpub,numpayments,payment,hashchain)!='O')
|
||||
{
|
||||
fprintf(stderr, "invalid channel open tx\n");
|
||||
return ("");
|
||||
}
|
||||
if (mypk != srcpub)
|
||||
{
|
||||
fprintf(stderr,"cannot refund, you are not the channel owenr\n");
|
||||
return("");
|
||||
}
|
||||
if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 )
|
||||
{
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk));
|
||||
mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('R',mypk,mypk,0,0,stoptxid)));
|
||||
if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && funds-txfee>0)
|
||||
{
|
||||
if ((GetTransaction(prevtxid,prevTx,hashblock,false) != 0) && (numvouts=prevTx.vout.size()) > 0 &&
|
||||
DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3) != 0)
|
||||
{
|
||||
hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash, channelOpenTx.vin[0].prevout.n,1);
|
||||
endiancpy(hash, (uint8_t * ) & hentropy, 32);
|
||||
for (i = 0; i < param1; i++)
|
||||
{
|
||||
vcalc_sha256(0, hashdest, hash, 32);
|
||||
memcpy(hash, hashdest, 32);
|
||||
}
|
||||
endiancpy((uint8_t * ) & secret, hashdest, 32);
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk));
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub));
|
||||
mtx.vout.push_back(CTxOut(funds-txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('R',opentxid,mypk,destpub,param1,payment,closetxid)));
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"previous tx is invalid\n");
|
||||
return("");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"error adding CC inputs\n");
|
||||
return("");
|
||||
}
|
||||
}
|
||||
return("");
|
||||
}
|
||||
|
||||
UniValue ChannelsInfo()
|
||||
UniValue ChannelsInfo(uint256 channeltxid)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); CTransaction tx; uint256 txid,hashBlock,hashchain; struct CCcontract_info *cp,C; uint8_t funcid; char myCCaddr[64]; int32_t vout,numvouts,numpayments; int64_t nValue,payment; CPubKey srcpub,destpub,mypk;
|
||||
UniValue result(UniValue::VOBJ); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,prevtxid;
|
||||
struct CCcontract_info *cp,C; char myCCaddr[65],addr[65],str1[512],str2[256]; int32_t vout,numvouts,param1,numpayments;
|
||||
int64_t nValue,param2,payment; CPubKey srcpub,destpub,mypk;
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > txids;
|
||||
|
||||
result.push_back(Pair("result","success"));
|
||||
result.push_back(Pair("name","Channels"));
|
||||
cp = CCinit(&C,EVAL_CHANNELS);
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
GetCCaddress(cp,myCCaddr,mypk);
|
||||
SetCCtxids(txids,myCCaddr);
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=txids.begin(); it!=txids.end(); it++)
|
||||
if (channeltxid==zeroid)
|
||||
{
|
||||
//int height = it->first.blockHeight;
|
||||
txid = it->first.txhash;
|
||||
vout = (int32_t)it->first.index;
|
||||
nValue = (int64_t)it->second;
|
||||
if ( (vout == 1 || vout == 2) && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 )
|
||||
result.push_back(Pair("name","Channels Info"));
|
||||
GetCCaddress(cp,myCCaddr,mypk);
|
||||
SetCCtxids(txids,myCCaddr);
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=txids.begin(); it!=txids.end(); it++)
|
||||
{
|
||||
if ( DecodeChannelsOpRet(txid,tx.vout[numvouts-1].scriptPubKey,srcpub,destpub,numpayments,payment,hashchain) == 'O' || funcid == 'P' )
|
||||
//int height = it->first.blockHeight;
|
||||
txid = it->first.txhash;
|
||||
vout = (int32_t)it->first.index;
|
||||
nValue = (int64_t)it->second;
|
||||
if ( (vout == 1 || vout == 2) && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 )
|
||||
{
|
||||
char str[67],str2[67];
|
||||
fprintf(stderr,"%s func.%c %s -> %s %.8f num.%d of %.8f\n",mypk == srcpub ? "send" : "recv",funcid,pubkey33_str(str,(uint8_t *)&srcpub),pubkey33_str(str2,(uint8_t *)&destpub),(double)tx.vout[0].nValue/COIN,numpayments,(double)payment/COIN);
|
||||
if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O')
|
||||
{
|
||||
GetCCaddress1of2(cp,addr,srcpub,destpub);
|
||||
sprintf(str1,"%s - %lld payments of %lld satoshi - %s",addr,(long long)param1,(long long)param2,tx.GetHash().ToString().c_str());
|
||||
result.push_back(Pair("Channel", str1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GetTransaction(channeltxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 &&
|
||||
(DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'O'))
|
||||
{
|
||||
GetCCaddress1of2(cp,addr,srcpub,destpub);
|
||||
sprintf(str1,"Channel %s",addr);
|
||||
result.push_back(Pair("name",str1));
|
||||
SetCCtxids(txids,addr);
|
||||
prevtxid=zeroid;
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=txids.begin(); it!=txids.end(); it++)
|
||||
{
|
||||
|
||||
txid = it->first.txhash;
|
||||
if (txid!=prevtxid && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 )
|
||||
{
|
||||
if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O' && tx.GetHash()==channeltxid)
|
||||
{
|
||||
sprintf(str1,"%lld payments of %lld satoshi",(long long)param1,(long long)param2);
|
||||
result.push_back(Pair("Open", str1));
|
||||
}
|
||||
else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'P' && opentxid==channeltxid)
|
||||
{
|
||||
if (GetTransaction(opentxid,opentx,hashBlock,false) != 0 && (numvouts=opentx.vout.size()) > 0 &&
|
||||
DecodeChannelsOpRet(opentx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,numpayments,payment,hashchain) == 'O')
|
||||
{
|
||||
Getscriptaddress(str2,tx.vout[3].scriptPubKey);
|
||||
sprintf(str1,"%lld satoshi to %s, %lld payments left",(long long)(param2*payment),str2,(long long)param1);
|
||||
result.push_back(Pair("Payment",str1));
|
||||
}
|
||||
}
|
||||
else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'C' && opentxid==channeltxid)
|
||||
{
|
||||
result.push_back(Pair("Close","channel"));
|
||||
}
|
||||
else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'R' && opentxid==channeltxid)
|
||||
{
|
||||
Getscriptaddress(str2,tx.vout[2].scriptPubKey);
|
||||
sprintf(str1,"%lld satoshi back to %s",(long long)(param1*param2),str2);
|
||||
result.push_back(Pair("Refund",str1));
|
||||
}
|
||||
}
|
||||
prevtxid=txid;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
6
src/cc/dapps/diceloop
Executable file
6
src/cc/dapps/diceloop
Executable file
@@ -0,0 +1,6 @@
|
||||
while true
|
||||
do
|
||||
./c dicestatus KMDICE 5be49570c56d036abb08b6d084da93a8a86f58fc48db4a1086be95540d752d6f
|
||||
|
||||
sleep 10
|
||||
done
|
||||
@@ -19,6 +19,8 @@
|
||||
#include <memory.h>
|
||||
#include "cJSON.c"
|
||||
|
||||
bits256 zeroid;
|
||||
|
||||
char hexbyte(int32_t c)
|
||||
{
|
||||
c &= 0xf;
|
||||
@@ -139,7 +141,7 @@ long _stripwhite(char *buf,int accept)
|
||||
char *clonestr(char *str)
|
||||
{
|
||||
char *clone;
|
||||
if ( str == 0 || str[0] == 0 )
|
||||
if ( str == 0 || str[0]==0)
|
||||
{
|
||||
printf("warning cloning nullstr.%p\n",str);
|
||||
//#ifdef __APPLE__
|
||||
@@ -330,7 +332,8 @@ cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char
|
||||
system(cmdstr);
|
||||
*retstrp = 0;
|
||||
if ( (jsonstr= filestr(&fsize,fname)) != 0 )
|
||||
{
|
||||
{
|
||||
jsonstr[strlen(jsonstr)-1]='\0';
|
||||
//fprintf(stderr,"%s -> jsonstr.(%s)\n",cmdstr,jsonstr);
|
||||
if ( (jsonstr[0] != '{' && jsonstr[0] != '[') || (retjson= cJSON_Parse(jsonstr)) == 0 )
|
||||
*retstrp = jsonstr;
|
||||
@@ -357,7 +360,7 @@ bits256 komodobroadcast(char *refcoin,char *acname,cJSON *hexjson)
|
||||
retstr[64] = 0;
|
||||
decode_hex(txid.bytes,32,retstr);
|
||||
}
|
||||
fprintf(stderr,"broadcast %s txid.(%s)\n",acname,bits256_str(str,txid));
|
||||
fprintf(stderr,"broadcast %s txid.(%s)\n",strlen(acname)>0?acname:refcoin,bits256_str(str,txid));
|
||||
free(retstr);
|
||||
}
|
||||
}
|
||||
@@ -464,10 +467,10 @@ int32_t get_coinheader(char *refcoin,char *acname,bits256 *blockhashp,bits256 *m
|
||||
return(0);
|
||||
}
|
||||
|
||||
cJSON *get_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr)
|
||||
cJSON *get_gatewayspending(char *refcoin,char *acname,char *bindtxidstr)
|
||||
{
|
||||
cJSON *retjson; char *retstr;
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspending",oraclestxidstr,refcoin,"","")) != 0 )
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspending",bindtxidstr,refcoin,"","")) != 0 )
|
||||
{
|
||||
//printf("pending.(%s)\n",jprint(retjson,0));
|
||||
return(retjson);
|
||||
@@ -530,6 +533,23 @@ cJSON *get_rawtransaction(char *refcoin,char *acname,bits256 txid)
|
||||
return(0);
|
||||
}
|
||||
|
||||
int32_t validateaddress(char *refcoin,char *acname,char *depositaddr, char* compare)
|
||||
{
|
||||
cJSON *retjson; char *retstr; int32_t res=0;
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"validateaddress",depositaddr,"","","")) != 0 )
|
||||
{
|
||||
if (is_cJSON_True(jobj(retjson,compare)) != 0 ) res=1;
|
||||
free_json(retjson);
|
||||
}
|
||||
else if ( retstr != 0 )
|
||||
{
|
||||
fprintf(stderr,"validateaddress.(%s) %s error.(%s)\n",refcoin,acname,retstr);
|
||||
free(retstr);
|
||||
}
|
||||
|
||||
return (res);
|
||||
}
|
||||
|
||||
void importaddress(char *refcoin,char *acname,char *depositaddr)
|
||||
{
|
||||
cJSON *retjson; char *retstr;
|
||||
@@ -545,6 +565,24 @@ void importaddress(char *refcoin,char *acname,char *depositaddr)
|
||||
}
|
||||
}
|
||||
|
||||
void addmultisigaddress(char *refcoin,char *acname,int32_t M, char *pubkeys,char *bindtxidstr)
|
||||
{
|
||||
cJSON *retjson; char *retstr,Mstr[10],tmp[128];
|
||||
|
||||
sprintf(Mstr,"%d",M);
|
||||
sprintf(tmp,"\"%s\"",bindtxidstr);
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"addmultisigaddress",Mstr,pubkeys,tmp,"")) != 0 )
|
||||
{
|
||||
fprintf(stderr,"unexpected addmultisigaddress json.(%s)\n",jprint(retjson,0));
|
||||
free(retstr);
|
||||
}
|
||||
else if ( retstr != 0 )
|
||||
{
|
||||
printf("addmultisigaddress.(%s)\n",retstr);
|
||||
free_json(retjson);
|
||||
}
|
||||
}
|
||||
|
||||
cJSON *getinputarray(int64_t *totalp,cJSON *unspents,int64_t required)
|
||||
{
|
||||
cJSON *vin,*item,*vins = cJSON_CreateArray(); int32_t i,n,v; int64_t satoshis; bits256 txid;
|
||||
@@ -584,7 +622,7 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad
|
||||
return(0);
|
||||
}
|
||||
satoshis -= txfee;
|
||||
sprintf(array,"[\"%s\"]",depositaddr);
|
||||
sprintf(array,"\'[\"%s\"]\'",depositaddr);
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"listunspent","1","99999999",array,"")) != 0 )
|
||||
{
|
||||
//createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,...}
|
||||
@@ -599,9 +637,12 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad
|
||||
change = (total - satoshis);
|
||||
jaddnum(vouts,depositaddr,(double)change/SATOSHIDEN);
|
||||
}
|
||||
char *argA,*argB;
|
||||
argA = jprint(vins,1);
|
||||
argB = jprint(vouts,1);
|
||||
char *tmpA=jprint(vins,1);
|
||||
char *tmpB=jprint(vouts,1);
|
||||
char *argA=malloc(sizeof(char) * (strlen(tmpA)+3));
|
||||
char *argB=malloc(sizeof(char) * (strlen(tmpB)+3));
|
||||
sprintf(argA,"\'%s\'",tmpA);
|
||||
sprintf(argB,"\'%s\'",tmpB);
|
||||
if ( (retjson2= get_komodocli(refcoin,&txstr,acname,"createrawtransaction",argA,argB,"","")) != 0 )
|
||||
{
|
||||
printf("createmultisig: unexpected JSON2.(%s)\n",jprint(retjson2,0));
|
||||
@@ -609,10 +650,13 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad
|
||||
}
|
||||
else if ( txstr == 0 )
|
||||
printf("createmultisig: null txstr and JSON2\n");
|
||||
free(tmpA);
|
||||
free(tmpB);
|
||||
free(argA);
|
||||
free(argB);
|
||||
}
|
||||
}
|
||||
free_json(retjson);
|
||||
}
|
||||
else if ( retstr != 0 )
|
||||
{
|
||||
@@ -628,7 +672,7 @@ cJSON *addmultisignature(char *refcoin,char *acname,char *signeraddr,char *rawtx
|
||||
char *retstr,*hexstr; cJSON *retjson;
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"signrawtransaction",rawtx,"","","")) != 0 )
|
||||
{
|
||||
if ( jint(retjson,"complete") != 0 )
|
||||
if ( is_cJSON_True(jobj(retjson,"complete")) != 0 )
|
||||
return(retjson);
|
||||
else if ( (hexstr= jstr(retjson,"hex")) != 0 && strlen(hexstr) > strlen(rawtx) )
|
||||
{
|
||||
@@ -640,18 +684,36 @@ cJSON *addmultisignature(char *refcoin,char *acname,char *signeraddr,char *rawtx
|
||||
return(0);
|
||||
}
|
||||
|
||||
char *get_gatewaysmultisig(char *refcoin,char *acname,char *bindtxidstr,char *withtxidstr,char *txidaddr)
|
||||
char *get_gatewaysmultisig(char *refcoin,char *acname,char *txidaddr,int32_t *K)
|
||||
{
|
||||
char *retstr,*hexstr,*hex=0; cJSON *retjson;
|
||||
if ( (retjson= get_komodocli("KMD",&retstr,acname,"gatewaysmultisig",bindtxidstr,refcoin,withtxidstr,txidaddr)) != 0 )
|
||||
if ( (retjson= get_komodocli("KMD",&retstr,acname,"gatewaysmultisig",txidaddr,"","","")) != 0 )
|
||||
{
|
||||
if ( (hexstr= jstr(retjson,"hex")) != 0 )
|
||||
hex = clonestr(hexstr);
|
||||
if ((hexstr=jstr(retjson,"hex")) != 0 )
|
||||
{
|
||||
if (strlen(hexstr)>0) hex = clonestr(hexstr);
|
||||
}
|
||||
*K=jint(retjson,"number_of_signs");
|
||||
free_json(retjson);
|
||||
}
|
||||
return(hex);
|
||||
}
|
||||
|
||||
bits256 gatewayspartialsign(char *refcoin,char *acname,bits256 txid,char *hex)
|
||||
{
|
||||
char str[65],*retstr; cJSON *retjson;
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspartialsign",bits256_str(str,txid),refcoin,hex,"")) != 0 )
|
||||
{
|
||||
return(komodobroadcast(refcoin,acname,retjson));
|
||||
}
|
||||
else if ( retstr != 0 )
|
||||
{
|
||||
printf("error parsing gatewayspartialsing.(%s)\n",retstr);
|
||||
free(retstr);
|
||||
}
|
||||
return (zeroid);
|
||||
}
|
||||
|
||||
void gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin,bits256 cointxid)
|
||||
{
|
||||
char str[65],str2[65],*retstr; cJSON *retjson;
|
||||
@@ -668,9 +730,9 @@ void gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin,bit
|
||||
}
|
||||
}
|
||||
|
||||
int32_t get_gatewaysinfo(char *refcoin,char *acname,char *depositaddr,int32_t *Mp,int32_t *Np,char *bindtxidstr,char *coin,char *oraclestr)
|
||||
int32_t get_gatewaysinfo(char *refcoin,char *acname,char *depositaddr,int32_t *Mp,int32_t *Np,char *bindtxidstr,char *coin,char *oraclestr, char **pubkeys)
|
||||
{
|
||||
char *oracle,*retstr,*name,*deposit; cJSON *retjson;
|
||||
char *oracle,*retstr,*name,*deposit,temp[128]; cJSON *retjson,*pubarray; int32_t n;
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysinfo",bindtxidstr,"","","")) != 0 )
|
||||
{
|
||||
if ( (oracle= jstr(retjson,"oracletxid")) != 0 && strcmp(oracle,oraclestr) == 0 && (deposit= jstr(retjson,"deposit")) != 0 )
|
||||
@@ -680,9 +742,23 @@ int32_t get_gatewaysinfo(char *refcoin,char *acname,char *depositaddr,int32_t *M
|
||||
{
|
||||
*Mp = jint(retjson,"M");
|
||||
*Np = jint(retjson,"N");
|
||||
//printf("(%s)\n",jprint(retjson,0));
|
||||
} else printf("coin.%s vs %s\n",jstr(retjson,"coin"),coin);
|
||||
} else printf("%s != %s\n",oracle,oraclestr);
|
||||
}
|
||||
else printf("coin.%s vs %s\n",jstr(retjson,"coin"),coin);
|
||||
if ((pubarray=jarray(&n,retjson,"pubkeys"))!=0)
|
||||
{
|
||||
*pubkeys=malloc((sizeof(char)*70*n)+64);
|
||||
sprintf(*pubkeys,"\"[");
|
||||
for (int i=0;i<n;i++)
|
||||
{
|
||||
sprintf(temp,"\\\"%s\\\"",jstri(pubarray,i));
|
||||
if (i<n-1) strcat(temp,",");
|
||||
strcat(*pubkeys,temp);
|
||||
}
|
||||
sprintf(temp,"]\"");
|
||||
strcat(*pubkeys,temp);
|
||||
}
|
||||
}
|
||||
else printf("%s != %s\n",oracle,oraclestr);
|
||||
free_json(retjson);
|
||||
}
|
||||
else if ( retstr != 0 )
|
||||
@@ -697,15 +773,14 @@ int32_t get_gatewaysinfo(char *refcoin,char *acname,char *depositaddr,int32_t *M
|
||||
|
||||
int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinaddr)
|
||||
{
|
||||
cJSON *txobj,*vouts,*vout,*sobj,*addresses; char *addr,str[65]; int32_t i,j,n,numvouts,retval = 0;
|
||||
cJSON *txobj,*vouts,*vout,*vins,*vin,*sobj,*addresses; char *addr,str[65]; int32_t i,j,n,numarray,retval = 0, hasvout=0;
|
||||
if ( (txobj= get_rawtransaction(refcoin,acname,txid)) != 0 )
|
||||
{
|
||||
if ( (vouts= jarray(&numvouts,txobj,"vout")) != 0 )
|
||||
if ( (vouts= jarray(&numarray,txobj,"vout")) != 0 )
|
||||
{
|
||||
for (i=0; i<numvouts; i++)
|
||||
{
|
||||
vout = jitem(vouts,i);
|
||||
if ( (sobj= jobj(vout,"scriptPubKey")) != 0 )
|
||||
for (i=0; i<numarray; i++)
|
||||
{
|
||||
if ((vout = jitem(vouts,i)) !=0 && (sobj= jobj(vout,"scriptPubKey")) != 0 )
|
||||
{
|
||||
if ( (addresses= jarray(&n,sobj,"addresses")) != 0 )
|
||||
{
|
||||
@@ -715,26 +790,55 @@ int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinadd
|
||||
if ( strcmp(addr,coinaddr) == 0 )
|
||||
{
|
||||
//fprintf(stderr,"found %s in %s v%d\n",coinaddr,bits256_str(str,txid),i);
|
||||
retval = 1;
|
||||
hasvout = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasvout==1) break;
|
||||
}
|
||||
}
|
||||
// if (hasvout==1 && (vins=jarray(&numarray,txobj,"vin"))!=0)
|
||||
// {
|
||||
// for (int i=0;i<numarray;i++)
|
||||
// {
|
||||
// if ((vin=jitem(vins,i))!=0 && validateaddress(refcoin,acname,jstr(vin,"address"),"ismine")!=0)
|
||||
// {
|
||||
// retval=1;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
free_json(txobj);
|
||||
}
|
||||
return(retval);
|
||||
return(hasvout);
|
||||
}
|
||||
|
||||
int32_t coinaddrexists(char *refcoin,char *acname,char *coinaddr)
|
||||
int32_t markerfromthisnodeorunconfirmed(char *refcoin,char *acname,char *coinaddr)
|
||||
{
|
||||
cJSON *array; bits256 txid; int32_t i,n,num=0;
|
||||
cJSON *array,*item,*rawtx,*vins,*vin; bits256 txid,tmptxid; int32_t i,n,m,num=0; char *retstr;
|
||||
if ( (array= get_addressutxos(refcoin,acname,coinaddr)) != 0 )
|
||||
{
|
||||
num = cJSON_GetArraySize(array);
|
||||
free_json(array);
|
||||
} else return(-1);
|
||||
n=cJSON_GetArraySize(array);
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
if ((item=jitem(array,i))!=0 && (bits256_nonz(tmptxid=jbits256(item,"txid")))!=0 && (rawtx=get_rawtransaction(refcoin,acname,tmptxid))!=0 && (vins=jarray(&m,rawtx,"vin"))!=0)
|
||||
{
|
||||
for (int j=0;j<m;j++)
|
||||
{
|
||||
if ((vin=jitem(vins,j))!=0 && validateaddress(refcoin,acname,jstr(vin,"address"),"ismine")!=0)
|
||||
{
|
||||
num=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (num==1) break;
|
||||
}
|
||||
free_json(array);
|
||||
}
|
||||
else return(-1);
|
||||
if ( num == 0 )
|
||||
{
|
||||
if ( (array= get_rawmempool(refcoin,acname)) != 0 )
|
||||
@@ -753,7 +857,7 @@ int32_t coinaddrexists(char *refcoin,char *acname,char *coinaddr)
|
||||
}
|
||||
free_json(array);
|
||||
} else return(-1);
|
||||
}
|
||||
}
|
||||
return(num);
|
||||
}
|
||||
|
||||
@@ -766,7 +870,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t
|
||||
/// if enough sigs, sendrawtransaction and when it confirms spend marker (txid.2)
|
||||
/// if not enough sigs, post partially signed to acname with marker2
|
||||
// monitor marker2, for the partially signed withdraws
|
||||
cJSON *retjson,*pending,*item,*clijson; char str[65],*rawtx,*coinstr,*txidaddr,*signeraddr,*depositaddr,*withdrawaddr; int32_t i,j,n,retval,processed = 0; bits256 txid,cointxid,origtxid,zeroid; int64_t satoshis;
|
||||
cJSON *retjson,*pending,*item,*clijson; char str[65],*rawtx,*coinstr,*txidaddr,*signeraddr,*depositaddr,*withdrawaddr; int32_t i,j,n,K,retval,processed = 0; bits256 txid,cointxid,origtxid; int64_t satoshis;
|
||||
memset(&zeroid,0,sizeof(zeroid));
|
||||
if ( (retjson= get_gatewayspending("KMD",acname,bindtxidstr)) != 0 )
|
||||
{
|
||||
@@ -783,17 +887,16 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t
|
||||
//process item.0 {"txid":"10ec8f4dad6903df6b249b361b879ac77b0617caad7629b97e10f29fa7e99a9b","txidaddr":"RMbite4TGugVmkGmu76ytPHDEQZQGSUjxz","withdrawaddr":"RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc","amount":"1.00000000","depositaddr":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj","signeraddr":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj"}
|
||||
if ( (txidaddr= jstr(item,"txidaddr")) != 0 && (withdrawaddr= jstr(item,"withdrawaddr")) != 0 && (depositaddr= jstr(item,"depositaddr")) != 0 && (signeraddr= jstr(item,"signeraddr")) != 0 )
|
||||
{
|
||||
if ( (satoshis= jdouble(item,"amount")*SATOSHIDEN) != 0 && (retval= coinaddrexists("KMD",acname,txidaddr)) == 0 )
|
||||
{
|
||||
// this is less errors but more expensive: ./komodo-cli z_sendmany "signeraddr" '[{"address":"<txidaddr>","amount":0.0001},{"address":"<withdrawaddr>","amount":<withamount>}]'
|
||||
txid = sendtoaddress("KMD",acname,txidaddr,10000);
|
||||
if ( bits256_nonz(txid) != 0 && coinaddrexists("KMD",acname,txidaddr) > 0 )
|
||||
if ( (satoshis= jdouble(item,"amount")*SATOSHIDEN) != 0 && markerfromthisnodeorunconfirmed("KMD",acname,txidaddr) == 0)
|
||||
{
|
||||
// the actual withdraw
|
||||
if ( strcmp(depositaddr,signeraddr) == 0 )
|
||||
{
|
||||
// the actual withdraw
|
||||
if ( strcmp(depositaddr,signeraddr) == 0 )
|
||||
txid= sendtoaddress("KMD",acname,txidaddr,10000);
|
||||
if (bits256_nonz(txid) != 0)
|
||||
{
|
||||
cointxid = sendtoaddress(refcoin,"",withdrawaddr,satoshis);
|
||||
if ( bits256_nonz(cointxid) != 0 )
|
||||
if ( bits256_nonz(cointxid) != 0)
|
||||
{
|
||||
fprintf(stderr,"withdraw %s %s %s %.8f processed\n",refcoin,bits256_str(str,cointxid),withdrawaddr,(double)satoshis/SATOSHIDEN);
|
||||
gatewaysmarkdone("KMD",acname,origtxid,refcoin,cointxid);
|
||||
@@ -806,42 +909,40 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( (rawtx= get_gatewaysmultisig(refcoin,acname,bindtxidstr,bits256_str(str,origtxid),txidaddr)) == 0 )
|
||||
{
|
||||
rawtx = createmultisig(refcoin,"",depositaddr,signeraddr,withdrawaddr,satoshis);
|
||||
}
|
||||
if ( rawtx != 0 )
|
||||
{
|
||||
if ( (clijson= addmultisignature(refcoin,"",signeraddr,rawtx)) != 0 )
|
||||
{
|
||||
if ( jint(clijson,"complete") != 0 )
|
||||
{
|
||||
cointxid = komodobroadcast(refcoin,"",clijson);
|
||||
if ( bits256_nonz(cointxid) != 0 )
|
||||
{
|
||||
fprintf(stderr,"withdraw %s M.%d N.%d %s %s %.8f processed\n",refcoin,M,N,bits256_str(str,cointxid),withdrawaddr,(double)satoshis/SATOSHIDEN);
|
||||
gatewaysmarkdone("KMD",acname,origtxid,refcoin,cointxid);
|
||||
}
|
||||
}
|
||||
else if ( jint(clijson,"partialtx") != 0 )
|
||||
{
|
||||
// 10000 + ith -> txidaddr
|
||||
txid = komodobroadcast("KMD",acname,clijson);
|
||||
fprintf(stderr,"%s M.%d of N.%d partialtx %s sent\n",refcoin,M,N,bits256_str(str,txid));
|
||||
}
|
||||
free_json(clijson);
|
||||
}
|
||||
processed++;
|
||||
free(rawtx);
|
||||
} else fprintf(stderr,"couldnt create msig rawtx\n");
|
||||
fprintf(stderr,"ERROR sending withdraw marker %s %s to %s %.8f processed\n",refcoin,bits256_str(str,cointxid),txidaddr,(double)10000/SATOSHIDEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( retval > 0 )
|
||||
{
|
||||
fprintf(stderr,"already did withdraw %s %s %.8f processed\n",refcoin,withdrawaddr,(double)satoshis/SATOSHIDEN);
|
||||
gatewaysmarkdone("KMD",acname,origtxid,refcoin,zeroid);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( (rawtx= get_gatewaysmultisig(refcoin,acname,txidaddr,&K)) == 0)
|
||||
{
|
||||
rawtx = createmultisig(refcoin,"",depositaddr,signeraddr,withdrawaddr,satoshis);
|
||||
}
|
||||
if ( rawtx != 0 )
|
||||
{
|
||||
if ( (clijson= addmultisignature(refcoin,"",signeraddr,rawtx)) != 0 )
|
||||
{
|
||||
if ( is_cJSON_True(jobj(clijson,"complete")) != 0 )
|
||||
{
|
||||
cointxid = komodobroadcast(refcoin,"",clijson);
|
||||
if ( bits256_nonz(cointxid) != 0 )
|
||||
{
|
||||
fprintf(stderr,"withdraw %s M.%d N.%d %s %s %.8f processed\n",refcoin,M,N,bits256_str(str,cointxid),withdrawaddr,(double)satoshis/SATOSHIDEN);
|
||||
gatewaysmarkdone("KMD",acname,origtxid,refcoin,cointxid);
|
||||
}
|
||||
}
|
||||
else if ( jint(clijson,"partialtx") != 0 )
|
||||
{
|
||||
txid=gatewayspartialsign(refcoin,acname,origtxid,jstr(clijson,"hex"));
|
||||
fprintf(stderr,"%d of %d partialtx %s sent\n",K+1,N,bits256_str(str,txid));
|
||||
}
|
||||
free_json(clijson);
|
||||
}
|
||||
processed++;
|
||||
free(rawtx);
|
||||
} else fprintf(stderr,"couldnt create msig rawtx\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -907,7 +1008,7 @@ oraclesdata 17a841a919c284cea8a676f34e793da002e606f19a9258a3190bed12d5aaa3ff 034
|
||||
|
||||
int32_t main(int32_t argc,char **argv)
|
||||
{
|
||||
cJSON *clijson,*clijson2,*regjson,*item; int32_t acheight,i,retval,M,N,n,height,prevheight = 0; char *format,*acname,*oraclestr,*bindtxidstr,*pkstr,*pubstr,*retstr,*retstr2,depositaddr[64],hexstr[4096],refcoin[64]; uint64_t price; bits256 txid;
|
||||
cJSON *clijson,*clijson2,*regjson,*item; int32_t acheight,i,retval,M,N,n,height,prevheight = 0; char *pubkeys,*format,*acname,*oraclestr,*bindtxidstr,*pkstr,*pubstr,*retstr,*retstr2,depositaddr[64],hexstr[4096],refcoin[64]; uint64_t price; bits256 txid;
|
||||
if ( argc < 6 )
|
||||
{
|
||||
printf("usage: oraclefeed $ACNAME $ORACLETXID $MYPUBKEY $FORMAT $BINDTXID [refcoin_cli]\n");
|
||||
@@ -943,12 +1044,18 @@ int32_t main(int32_t argc,char **argv)
|
||||
printf("need to specify path to refcoin's cli as last argv\n");
|
||||
exit(0);
|
||||
}
|
||||
if ( get_gatewaysinfo("KMD",acname,depositaddr,&M,&N,bindtxidstr,refcoin,oraclestr) < 0 )
|
||||
pubkeys=0;
|
||||
if ( get_gatewaysinfo("KMD",acname,depositaddr,&M,&N,bindtxidstr,refcoin,oraclestr,&pubkeys) < 0 )
|
||||
{
|
||||
printf("cant find bindtxid.(%s)\n",bindtxidstr);
|
||||
exit(0);
|
||||
}
|
||||
importaddress(refcoin,"",depositaddr);
|
||||
if (validateaddress(refcoin,"",depositaddr,"iswatchonly")==0)
|
||||
{
|
||||
if (M==N==1) importaddress(refcoin,"",depositaddr);
|
||||
else addmultisigaddress(refcoin,"",M,pubkeys,bindtxidstr);
|
||||
}
|
||||
if (pubkeys!=0) free(pubkeys);
|
||||
printf("set refcoin %s <- %s [%s] M.%d of N.%d\n",depositaddr,refcoin,REFCOIN_CLI,M,N);
|
||||
}
|
||||
if ( (regjson= jarray(&n,clijson,"registered")) != 0 )
|
||||
|
||||
3
src/cc/dapps/sendmany
Executable file
3
src/cc/dapps/sendmany
Executable file
@@ -0,0 +1,3 @@
|
||||
export addr="RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo"
|
||||
./komodo-cli -ac_name=KMDICE sendmany "" "{\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023}"
|
||||
|
||||
2
src/cc/dapps/sendmany100
Executable file
2
src/cc/dapps/sendmany100
Executable file
@@ -0,0 +1,2 @@
|
||||
./komodo-cli -ac_name=KMDICE sendmany "" "{\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002}"
|
||||
|
||||
1025
src/cc/dice.cpp
1025
src/cc/dice.cpp
File diff suppressed because it is too large
Load Diff
@@ -76,11 +76,11 @@ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn)
|
||||
case EVAL_IMPORTPAYOUT:
|
||||
return ImportPayout(vparams, txTo, nIn);
|
||||
break;
|
||||
|
||||
|
||||
case EVAL_IMPORTCOIN:
|
||||
return ImportCoin(vparams, txTo, nIn);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
return(ProcessCC(cp,this, vparams, txTo, nIn));
|
||||
break;
|
||||
@@ -98,10 +98,9 @@ bool Eval::GetSpendsConfirmed(uint256 hash, std::vector<CTransaction> &spends) c
|
||||
|
||||
bool Eval::GetTxUnconfirmed(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) const
|
||||
{
|
||||
// there is a LOCK(cs_main) in the normal GetTransaction(), which leads to deadlocks
|
||||
//bool fAllowSlow = false; // Don't allow slow
|
||||
//return GetTransaction(hash, txOut, hashBlock, fAllowSlow);
|
||||
return myGetTransaction(hash, txOut,hashBlock);
|
||||
if (!myGetTransaction(hash, txOut,hashBlock)) {
|
||||
return(GetTransaction(hash, txOut,hashBlock));
|
||||
} else return(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +114,6 @@ bool Eval::GetTxConfirmed(const uint256 &hash, CTransaction &txOut, CBlockIndex
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
unsigned int Eval::GetCurrentHeight() const
|
||||
{
|
||||
return chainActive.Height();
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
EVAL(EVAL_FSM, 0xe7) \
|
||||
EVAL(EVAL_AUCTION, 0xe8) \
|
||||
EVAL(EVAL_LOTTO, 0xe9) \
|
||||
EVAL(EVAL_MOFN, 0xea) \
|
||||
EVAL(EVAL_HEIR, 0xea) \
|
||||
EVAL(EVAL_CHANNELS, 0xeb) \
|
||||
EVAL(EVAL_ORACLES, 0xec) \
|
||||
EVAL(EVAL_PRICES, 0xed) \
|
||||
|
||||
@@ -142,14 +142,17 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx
|
||||
|
||||
int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs)
|
||||
{
|
||||
char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector<uint8_t> origpubkey; CTransaction vintx; int32_t vout,n = 0;
|
||||
char coinaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector<uint8_t> origpubkey; CTransaction vintx; int32_t vout,n = 0;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
GetCCaddress(cp,coinaddr,pk);
|
||||
SetCCunspents(unspentOutputs,coinaddr);
|
||||
threshold = total/maxinputs;
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
vout = (int32_t)it->first.index;
|
||||
if ( it->second.satoshis < threshold )
|
||||
continue;
|
||||
//char str[65]; fprintf(stderr,"check %s/v%d %.8f`\n",uint256_str(str,txid),vout,(double)it->second.satoshis/COIN);
|
||||
// no need to prevent dup
|
||||
if ( GetTransaction(txid,vintx,hashBlock,false) != 0 )
|
||||
|
||||
@@ -122,6 +122,7 @@ bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx)
|
||||
|
||||
int64_t AddFSMInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs)
|
||||
{
|
||||
// add threshold check
|
||||
char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector<uint8_t> origpubkey; CTransaction vintx; int32_t n = 0;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
GetCCaddress(cp,coinaddr,pk);
|
||||
|
||||
@@ -143,7 +143,7 @@
|
||||
*/
|
||||
|
||||
|
||||
int32_t GatewaysAddQueue(std::string coin,uint256 txid,CScript scriptPubKey,int64_t nValue)
|
||||
void GatewaysAddQueue(std::string coin,uint256 txid,CScript scriptPubKey,int64_t nValue)
|
||||
{
|
||||
char destaddr[64],str[65];
|
||||
Getscriptaddress(destaddr,scriptPubKey);
|
||||
@@ -178,6 +178,41 @@ uint8_t DecodeGatewaysOpRet(const CScript &scriptPubKey,std::string &coin,uint25
|
||||
return(0);
|
||||
}
|
||||
|
||||
uint8_t DecodeGatewaysPartialOpRet(const CScript &scriptPubKey,int32_t &K, CPubKey &signerpk, std::string &coin,std::string &hex)
|
||||
{
|
||||
std::vector<uint8_t> vopret; uint8_t *script,e,f;
|
||||
GetOpReturnData(scriptPubKey, vopret);
|
||||
script = (uint8_t *)vopret.data();
|
||||
if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> K; ss >> signerpk; ss >> coin; ss >> hex) != 0 )
|
||||
{
|
||||
return(f);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
uint8_t DecodeGatewaysWithdrawOpRet(const CScript &scriptPubKey, uint256 &assetid, std::string &refcoin, CPubKey &withdrawpub, int64_t &amount)
|
||||
{
|
||||
std::vector<uint8_t> vopret; uint8_t *script,e,f;
|
||||
GetOpReturnData(scriptPubKey, vopret);
|
||||
script = (uint8_t *)vopret.data();
|
||||
if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> refcoin; ss >> withdrawpub; ss >> amount) != 0 )
|
||||
{
|
||||
return(f);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
uint8_t DecodeGatewaysMarkdoneOpRet(const CScript &scriptPubKey, std::string &refcoin, uint256 &cointxid)
|
||||
{
|
||||
std::vector<uint8_t> vopret; uint8_t *script,e,f;
|
||||
GetOpReturnData(scriptPubKey, vopret);
|
||||
script = (uint8_t *)vopret.data();
|
||||
if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> refcoin; ss >> cointxid) != 0 )
|
||||
{
|
||||
return(f);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,std::string &coin,uint256 &tokenid,int64_t &totalsupply,uint256 &oracletxid,uint8_t &M,uint8_t &N,std::vector<CPubKey> &pubkeys,uint8_t &taddr,uint8_t &prefix,uint8_t &prefix2)
|
||||
{
|
||||
std::vector<uint8_t> vopret; uint8_t *script,e,f;
|
||||
@@ -189,8 +224,11 @@ uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,st
|
||||
if ( prefix == 60 )
|
||||
{
|
||||
if ( N > 1 )
|
||||
Getscriptaddress(depositaddr,GetScriptForMultisig(M,pubkeys));
|
||||
else Getscriptaddress(depositaddr,CScript() << ParseHex(HexStr(pubkeys[0])) << OP_CHECKSIG);
|
||||
{
|
||||
strcpy(depositaddr,CBitcoinAddress(CScriptID(GetScriptForMultisig(M,pubkeys))).ToString().c_str());
|
||||
//Getscriptaddress(depositaddr,GetScriptForMultisig(M,pubkeys));
|
||||
fprintf(stderr,"f.%c M.%d of N.%d size.%d -> %s\n",f,M,N,(int32_t)pubkeys.size(),depositaddr);
|
||||
} else Getscriptaddress(depositaddr,CScript() << ParseHex(HexStr(pubkeys[0])) << OP_CHECKSIG);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -294,15 +332,18 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
|
||||
|
||||
int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 refassetid,int64_t total,int32_t maxinputs)
|
||||
{
|
||||
char coinaddr[64],destaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 assetid,txid,hashBlock; std::vector<uint8_t> origpubkey; std::vector<uint8_t> vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid;
|
||||
char coinaddr[64],destaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 assetid,txid,hashBlock; std::vector<uint8_t> origpubkey; std::vector<uint8_t> vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
GetCCaddress(cp,coinaddr,pk);
|
||||
SetCCunspents(unspentOutputs,coinaddr);
|
||||
threshold = total/maxinputs;
|
||||
fprintf(stderr,"check %s for gateway inputs\n",coinaddr);
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
vout = (int32_t)it->first.index;
|
||||
if ( it->second.satoshis < threshold )
|
||||
continue;
|
||||
for (j=0; j<mtx.vin.size(); j++)
|
||||
if ( txid == mtx.vin[j].prevout.hash && vout == mtx.vin[j].prevout.n )
|
||||
break;
|
||||
@@ -311,14 +352,14 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP
|
||||
if ( GetTransaction(txid,vintx,hashBlock,false) != 0 )
|
||||
{
|
||||
Getscriptaddress(destaddr,vintx.vout[vout].scriptPubKey);
|
||||
//fprintf(stderr,"%s vout.%d %.8f %.8f\n",destaddr,vout,(double)vintx.vout[vout].nValue/COIN,(double)it->second.satoshis/COIN);
|
||||
fprintf(stderr,"check %s vout.%d %.8f %.8f\n",destaddr,vout,(double)vintx.vout[vout].nValue/COIN,(double)it->second.satoshis/COIN);
|
||||
if ( strcmp(destaddr,coinaddr) != 0 && strcmp(destaddr,cp->unspendableCCaddr) != 0 && strcmp(destaddr,cp->unspendableaddr2) != 0 )
|
||||
continue;
|
||||
GetOpReturnData(vintx.vout[vintx.vout.size()-1].scriptPubKey, vopret);
|
||||
if ( E_UNMARSHAL(vopret,ss >> evalcode; ss >> funcid; ss >> assetid) != 0 )
|
||||
{
|
||||
assetid = revuint256(assetid);
|
||||
//char str[65],str2[65]; fprintf(stderr,"vout.%d %d:%d (%c) check for refassetid.%s vs %s %.8f\n",vout,evalcode,cp->evalcode,funcid,uint256_str(str,refassetid),uint256_str(str2,assetid),(double)vintx.vout[vout].nValue/COIN);
|
||||
char str[65],str2[65]; fprintf(stderr,"vout.%d %d:%d (%c) check for refassetid.%s vs %s %.8f\n",vout,evalcode,cp->evalcode,funcid,uint256_str(str,refassetid),uint256_str(str2,assetid),(double)vintx.vout[vout].nValue/COIN);
|
||||
if ( assetid == refassetid && funcid == 't' && (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 )
|
||||
{
|
||||
//fprintf(stderr,"total %llu maxinputs.%d %.8f\n",(long long)total,maxinputs,(double)it->second.satoshis/COIN);
|
||||
@@ -426,7 +467,7 @@ UniValue GatewaysInfo(uint256 bindtxid)
|
||||
result.push_back(Pair("tokenid",uint256_str(str,tokenid)));
|
||||
sprintf(numstr,"%.8f",(double)totalsupply/COIN);
|
||||
result.push_back(Pair("totalsupply",numstr));
|
||||
remaining = CCaddress_balance(gatewaysassets);
|
||||
remaining = CCtoken_balance(gatewaysassets,tokenid);
|
||||
sprintf(numstr,"%.8f",(double)remaining/COIN);
|
||||
result.push_back(Pair("remaining",numstr));
|
||||
sprintf(numstr,"%.8f",(double)(totalsupply - remaining)/COIN);
|
||||
@@ -704,7 +745,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std::
|
||||
}
|
||||
if ( AddNormalinputs(mtx,mypk,3*txfee,60) > 0 )
|
||||
{
|
||||
mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,mypk));
|
||||
mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,destpub));
|
||||
mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,cointxid))) << OP_CHECKSIG));
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeGatewaysOpRet('D',coin,bindtxid,publishers,txids,height,cointxid,deposithex,proof,destpub,amount)));
|
||||
}
|
||||
@@ -714,7 +755,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std::
|
||||
|
||||
std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount)
|
||||
{
|
||||
CMutableTransaction mtx; CTransaction tx; CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; uint8_t M,N,taddr,prefix,prefix2; std::string coin; std::vector<CPubKey> msigpubkeys; int64_t totalsupply,depositamount,inputs,CCchange=0; int32_t numvouts; uint256 hashBlock,assetid,oracletxid; char str[65],depositaddr[64],coinaddr[64];
|
||||
CMutableTransaction mtx; CTransaction tx; CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; uint8_t M,N,taddr,prefix,prefix2; std::string coin; std::vector<CPubKey> msigpubkeys; int64_t totalsupply,depositamount,inputs,CCchange=0; int32_t numvouts; uint256 hashBlock,assetid,oracletxid; char str[65],depositaddr[64],coinaddr[64],destaddr[64];
|
||||
cp = CCinit(&C,EVAL_GATEWAYS);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
@@ -747,6 +788,8 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui
|
||||
{
|
||||
if ( inputs > amount )
|
||||
CCchange = (inputs - amount);
|
||||
_GetCCaddress(destaddr,EVAL_GATEWAYS,mypk);
|
||||
printf("expecting deposittxid/v0 to be to %s\n",destaddr);
|
||||
mtx.vin.push_back(CTxIn(deposittxid,0,CScript())); // triggers EVAL_GATEWAYS validation
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,amount,mypk)); // transfer back to normal token
|
||||
if ( CCchange != 0 )
|
||||
@@ -758,9 +801,11 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui
|
||||
return("");
|
||||
}
|
||||
|
||||
std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,std::vector<uint8_t> withdrawpub,int64_t amount)
|
||||
std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,CPubKey withdrawpub,int64_t amount)
|
||||
{
|
||||
CMutableTransaction mtx; CTransaction tx; CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; uint256 assetid,hashBlock,oracletxid; int32_t numvouts; int64_t totalsupply,inputs,CCchange=0; uint8_t M,N,taddr,prefix,prefix2; std::string coin; std::vector<CPubKey> msigpubkeys; char depositaddr[64],str[65],coinaddr[64];
|
||||
CMutableTransaction mtx; CTransaction tx; CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C;
|
||||
uint256 assetid,hashBlock,oracletxid; int32_t numvouts; int64_t totalsupply,inputs,CCchange=0; uint8_t M,N,taddr,prefix,prefix2; std::string coin;
|
||||
std::vector<CPubKey> msigpubkeys; char depositaddr[64],str[65],coinaddr[64]; CScript opret;
|
||||
cp = CCinit(&C,EVAL_GATEWAYS);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
@@ -783,11 +828,12 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin
|
||||
if ( inputs > amount )
|
||||
CCchange = (inputs - amount);
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,amount,gatewayspk));
|
||||
mtx.vout.push_back(CTxOut(txfee,CScript() << withdrawpub << OP_CHECKSIG));
|
||||
mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(gatewayspk)) << OP_CHECKSIG));
|
||||
mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(withdrawpub)) << OP_CHECKSIG));
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,txfee,gatewayspk));
|
||||
if ( CCchange != 0 )
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,CCchange,mypk));
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey())));
|
||||
opret << OP_RETURN << E_MARSHAL(ss << cp->evalcode << 'W' << assetid << refcoin << withdrawpub << amount);
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret));
|
||||
}
|
||||
}
|
||||
fprintf(stderr,"cant find enough inputs or mismatched total\n");
|
||||
@@ -801,6 +847,7 @@ std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid,std::string ref
|
||||
if ( txfee == 0 )
|
||||
txfee = 5000;
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
|
||||
mtx.vin.push_back(CTxIn(withdrawtxid,2,CScript()));
|
||||
mtx.vout.push_back(CTxOut(5000,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
|
||||
opret << OP_RETURN << E_MARSHAL(ss << cp->evalcode << 'M' << cointxid << refcoin);
|
||||
@@ -809,8 +856,12 @@ std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid,std::string ref
|
||||
|
||||
UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ),pending(UniValue::VARR),obj(UniValue::VOBJ); CTransaction tx; std::string coin; CPubKey mypk,gatewayspk; std::vector<CPubKey> msigpubkeys; uint256 hashBlock,assetid,txid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; char depositaddr[64],withmarker[64],coinaddr[64],destaddr[64],str[65],withaddr[64],numstr[32],txidaddr[64],signeraddr[64]; int32_t i,n,numvouts,vout,numqueued,queueflag; int64_t totalsupply; struct CCcontract_info *cp,C;
|
||||
UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string coin,tmprefcoin; CPubKey mypk,gatewayspk,withdrawpub; std::vector<CPubKey> msigpubkeys;
|
||||
uint256 cointxid,hashBlock,assetid,txid,oracletxid; uint8_t M,N,taddr,prefix,prefix2;
|
||||
char depositaddr[64],withmarker[64],coinaddr[64],destaddr[64],str[65],withaddr[64],numstr[32],txidaddr[64],signeraddr[64];
|
||||
int32_t i,n,numvouts,vout,numqueued,queueflag; int64_t totalsupply,amount,nValue; struct CCcontract_info *cp,C;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
|
||||
cp = CCinit(&C,EVAL_GATEWAYS);
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
gatewayspk = GetUnspendable(cp,0);
|
||||
@@ -832,20 +883,23 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin)
|
||||
{
|
||||
queueflag = 1;
|
||||
break;
|
||||
}
|
||||
Getscriptaddress(withmarker,CScript() << ParseHex(HexStr(gatewayspk)) << OP_CHECKSIG);
|
||||
SetCCunspents(unspentOutputs,withmarker);
|
||||
}
|
||||
SetCCunspents(unspentOutputs,coinaddr);
|
||||
numqueued = 0;
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
vout = (int32_t)it->first.index;
|
||||
if ( GetTransaction(txid,tx,hashBlock,false) != 0 )
|
||||
nValue = (int64_t)it->second.satoshis;
|
||||
fprintf(stderr,"%s %d %ld\n",txid.ToString().c_str(),vout,(long)nValue);
|
||||
if ( vout == 2 && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) &&
|
||||
DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,tmprefcoin,withdrawpub,amount) == 'W' && myIsutxo_spentinmempool(txid,vout) == 0)
|
||||
{
|
||||
Getscriptaddress(destaddr,tx.vout[0].scriptPubKey);
|
||||
Getscriptaddress(withaddr,tx.vout[1].scriptPubKey);
|
||||
if ( strcmp(destaddr,coinaddr) == 0 )
|
||||
{
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.push_back(Pair("txid",uint256_str(str,txid)));
|
||||
CCtxidaddr(txidaddr,txid);
|
||||
obj.push_back(Pair("txidaddr",txidaddr));
|
||||
@@ -868,31 +922,72 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin)
|
||||
return(result);
|
||||
}
|
||||
|
||||
std::string GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,uint256 withdrawtxid,char *txidaddr)
|
||||
UniValue GatewaysMultisig(char *txidaddr)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); std::string coin,hex; char str[67],numstr[65],depositaddr[64],gatewaysassets[64]; uint8_t M,N; std::vector<CPubKey> pubkeys; uint8_t taddr,prefix,prefix2; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; CPubKey Gatewayspk,mypk; struct CCcontract_info *cp,C; int32_t i,n,complete,partialtx; int64_t totalsupply;
|
||||
cp = CCinit(&C,EVAL_GATEWAYS);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
complete = partialtx = 0;
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
Gatewayspk = GetUnspendable(cp,0);
|
||||
_GetCCaddress(gatewaysassets,EVAL_GATEWAYS,Gatewayspk);
|
||||
if ( GetTransaction(bindtxid,tx,hashBlock,false) != 0 )
|
||||
std::string parthex,hex,refcoin; uint256 txid,hashBlock; CTransaction tx; int32_t i,maxK,K,numvouts; CPubKey signerpk;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; UniValue result(UniValue::VOBJ);
|
||||
|
||||
SetCCunspents(unspentOutputs,txidaddr);
|
||||
maxK=0;
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
|
||||
{
|
||||
depositaddr[0] = 0;
|
||||
if ( tx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,tx.vout[tx.vout.size()-1].scriptPubKey,coin,tokenid,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 0 && M <= N && N > 1 && coin == refcoin )
|
||||
txid = it->first.txhash;
|
||||
if (GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0 && DecodeGatewaysPartialOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,K,signerpk,refcoin,hex) == 'P' && K>maxK )
|
||||
{
|
||||
// need a decentralized way to add signatures to msig tx
|
||||
n = pubkeys.size();
|
||||
for (i=0; i<n; i++)
|
||||
if ( mypk == pubkeys[i] )
|
||||
break;
|
||||
if ( i != n )
|
||||
{
|
||||
hex = "";
|
||||
} else fprintf(stderr,"not one of the multisig signers\n");
|
||||
maxK=K;
|
||||
parthex=hex;
|
||||
}
|
||||
}
|
||||
return(hex);
|
||||
|
||||
BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx)
|
||||
{
|
||||
const CTransaction &txmempool = e.GetTx();
|
||||
const uint256 &hash = txmempool.GetHash();
|
||||
|
||||
if ((numvouts=txmempool.vout.size()) > 0 && DecodeGatewaysPartialOpRet(txmempool.vout[numvouts-1].scriptPubKey,K,signerpk,refcoin,hex) == 'P' && K>maxK)
|
||||
{
|
||||
maxK=K;
|
||||
parthex=hex;
|
||||
}
|
||||
}
|
||||
|
||||
result.push_back(Pair("hex",parthex));
|
||||
result.push_back(Pair("number_of_signs",maxK));
|
||||
return (result);
|
||||
}
|
||||
|
||||
std::string GatewaysPartialSign(uint64_t txfee,uint256 txid,std::string refcoin, std::string hex)
|
||||
{
|
||||
CMutableTransaction mtx; CScript opret; CPubKey mypk,txidaddrpk,signerpk; struct CCcontract_info *cp,C; CTransaction tx;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; char txidaddr[65];
|
||||
int32_t maxK,K=0; uint256 tmptxid,parttxid,hashBlock;
|
||||
cp = CCinit(&C,EVAL_GATEWAYS);
|
||||
if ( txfee == 0 )
|
||||
txfee = 5000;
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
txidaddrpk=CCtxidaddr(txidaddr,txid);
|
||||
SetCCunspents(unspentOutputs,txidaddr);
|
||||
maxK=0;
|
||||
if (unspentOutputs.size()==0)
|
||||
{
|
||||
if (AddNormalinputs(mtx,mypk,2*txfee,2)==0) fprintf(stderr,"error adding funds for partialsign\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
|
||||
{
|
||||
tmptxid = it->first.txhash;
|
||||
if (GetTransaction(tmptxid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && DecodeGatewaysPartialOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,K,signerpk,refcoin,hex) == 'P' && K>maxK )
|
||||
{
|
||||
maxK=K;
|
||||
parttxid=tmptxid;
|
||||
}
|
||||
}
|
||||
if (maxK>0) mtx.vin.push_back(CTxIn(parttxid,0,CScript()));
|
||||
else fprintf(stderr,"Error finding previous partial tx\n");
|
||||
}
|
||||
|
||||
mtx.vout.push_back(CTxOut(5000,CScript() << ParseHex(HexStr(txidaddrpk)) << OP_CHECKSIG));
|
||||
opret << OP_RETURN << E_MARSHAL(ss << cp->evalcode << 'P' << maxK+1 << mypk << refcoin << hex);
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret));
|
||||
}
|
||||
|
||||
@@ -13,30 +13,16 @@
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "CCMofN.h"
|
||||
#include "CCHeir.h"
|
||||
|
||||
/*
|
||||
The idea of MofN CC is to allow non-interactive multisig, preferably in a cross chain compatible way, ie. for actual bitcoin multisig.
|
||||
|
||||
full redeemscript in an initial tx with opreturn
|
||||
ability to post partial signatures and construct a full transaction from M such partial signatures
|
||||
a new transaction would refer to the initialtx and other partial would refer to both
|
||||
|
||||
There is no need for a CC contract to use it for normal multisig as normal multisig transactions are already supported.
|
||||
|
||||
In order to take advantage of CC powers, we can create a more powerful multisig using shamir's secret MofN (up to 255) algo to allow spends. Using the same non-interactive partial signing is possible. also, in addition to spending, data payload can have additional data that is also revealed when the funds are spent.
|
||||
|
||||
rpc calls needed:
|
||||
1) create msig address (normal or shamir)
|
||||
2) post payment with partial sig
|
||||
3) add partial sig to 2)
|
||||
4) combine and submit M partial sigs
|
||||
|
||||
The idea of Heir CC is to allow crypto inheritance.
|
||||
A special 1of2 CC address is created that is freely spendable by the creator. The heir is only allowed to spend after the specified amount of idle blocks. The idea is that if the address doesnt spend any funds for a year (or whatever amount set), then it is time to allow the heir to spend. The design requires the heir to spend all the funds at once
|
||||
*/
|
||||
|
||||
// start of consensus code
|
||||
|
||||
int64_t IsMofNvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v)
|
||||
int64_t IsHeirvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v)
|
||||
{
|
||||
char destaddr[64];
|
||||
if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 )
|
||||
@@ -47,7 +33,7 @@ int64_t IsMofNvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v)
|
||||
return(0);
|
||||
}
|
||||
|
||||
bool MofNExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee)
|
||||
bool HeirExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee)
|
||||
{
|
||||
static uint256 zerohash;
|
||||
CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis;
|
||||
@@ -65,8 +51,8 @@ bool MofNExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &
|
||||
{
|
||||
//fprintf(stderr,"vini.%d check hash and vout\n",i);
|
||||
if ( hashBlock == zerohash )
|
||||
return eval->Invalid("cant MofN from mempool");
|
||||
if ( (assetoshis= IsMofNvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 )
|
||||
return eval->Invalid("cant Heir from mempool");
|
||||
if ( (assetoshis= IsHeirvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 )
|
||||
inputs += assetoshis;
|
||||
}
|
||||
}
|
||||
@@ -74,7 +60,7 @@ bool MofNExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &
|
||||
for (i=0; i<numvouts; i++)
|
||||
{
|
||||
//fprintf(stderr,"i.%d of numvouts.%d\n",i,numvouts);
|
||||
if ( (assetoshis= IsMofNvout(cp,tx,i)) != 0 )
|
||||
if ( (assetoshis= IsHeirvout(cp,tx,i)) != 0 )
|
||||
outputs += assetoshis;
|
||||
}
|
||||
if ( inputs != outputs+txfee )
|
||||
@@ -85,7 +71,7 @@ bool MofNExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &
|
||||
else return(true);
|
||||
}
|
||||
|
||||
bool MofNValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx)
|
||||
bool HeirValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx)
|
||||
{
|
||||
int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64];
|
||||
return(false);
|
||||
@@ -105,9 +91,9 @@ bool MofNValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx)
|
||||
}
|
||||
}
|
||||
//fprintf(stderr,"check amounts\n");
|
||||
if ( MofNExactAmounts(cp,eval,tx,1,10000) == false )
|
||||
if ( HeirExactAmounts(cp,eval,tx,1,10000) == false )
|
||||
{
|
||||
fprintf(stderr,"mofnget invalid amount\n");
|
||||
fprintf(stderr,"Heirget invalid amount\n");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@@ -116,8 +102,8 @@ bool MofNValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx)
|
||||
memcpy(hash,&txid,sizeof(hash));
|
||||
retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts);
|
||||
if ( retval != 0 )
|
||||
fprintf(stderr,"mofnget validated\n");
|
||||
else fprintf(stderr,"mofnget invalid\n");
|
||||
fprintf(stderr,"Heirget validated\n");
|
||||
else fprintf(stderr,"Heirget invalid\n");
|
||||
return(retval);
|
||||
}
|
||||
}
|
||||
@@ -126,8 +112,9 @@ bool MofNValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx)
|
||||
|
||||
// helper functions for rpc calls in rpcwallet.cpp
|
||||
|
||||
int64_t AddMofNInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs)
|
||||
int64_t AddHeirInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs)
|
||||
{
|
||||
// add threshold check
|
||||
char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector<uint8_t> origpubkey; CTransaction vintx; int32_t vout,n = 0;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
GetCCaddress(cp,coinaddr,pk);
|
||||
@@ -139,7 +126,7 @@ int64_t AddMofNInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKe
|
||||
// no need to prevent dup
|
||||
if ( GetTransaction(txid,vintx,hashBlock,false) != 0 )
|
||||
{
|
||||
if ( (nValue= IsMofNvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 )
|
||||
if ( (nValue= IsHeirvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 )
|
||||
{
|
||||
if ( total != 0 && maxinputs != 0 )
|
||||
mtx.vin.push_back(CTxIn(txid,vout,CScript()));
|
||||
@@ -154,27 +141,27 @@ int64_t AddMofNInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKe
|
||||
return(totalinputs);
|
||||
}
|
||||
|
||||
std::string MofNGet(uint64_t txfee,int64_t nValue)
|
||||
std::string HeirGet(uint64_t txfee,int64_t nValue)
|
||||
{
|
||||
CMutableTransaction mtx,tmpmtx; CPubKey mypk,mofnpk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash;
|
||||
cp = CCinit(&C,EVAL_MOFN);
|
||||
CMutableTransaction mtx,tmpmtx; CPubKey mypk,Heirpk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash;
|
||||
cp = CCinit(&C,EVAL_HEIR);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
mofnpk = GetUnspendable(cp,0);
|
||||
Heirpk = GetUnspendable(cp,0);
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
if ( (inputs= AddMofNInputs(cp,mtx,mofnpk,nValue+txfee,60)) > 0 )
|
||||
if ( (inputs= AddHeirInputs(cp,mtx,Heirpk,nValue+txfee,60)) > 0 )
|
||||
{
|
||||
if ( inputs > nValue )
|
||||
CCchange = (inputs - nValue - txfee);
|
||||
if ( CCchange != 0 )
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_MOFN,CCchange,mofnpk));
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_HEIR,CCchange,Heirpk));
|
||||
mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
|
||||
fprintf(stderr,"start at %u\n",(uint32_t)time(NULL));
|
||||
j = rand() & 0xfffffff;
|
||||
for (i=0; i<1000000; i++,j++)
|
||||
{
|
||||
tmpmtx = mtx;
|
||||
rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_MOFN << (uint8_t)'G' << j));
|
||||
rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'G' << j));
|
||||
if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 )
|
||||
{
|
||||
len >>= 1;
|
||||
@@ -190,35 +177,35 @@ std::string MofNGet(uint64_t txfee,int64_t nValue)
|
||||
}
|
||||
fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL));
|
||||
return("");
|
||||
} else fprintf(stderr,"cant find mofn inputs\n");
|
||||
} else fprintf(stderr,"cant find Heir inputs\n");
|
||||
return("");
|
||||
}
|
||||
|
||||
std::string MofNFund(uint64_t txfee,int64_t funds)
|
||||
std::string HeirFund(uint64_t txfee,int64_t funds)
|
||||
{
|
||||
CMutableTransaction mtx; CPubKey mypk,mofnpk; CScript opret; struct CCcontract_info *cp,C;
|
||||
cp = CCinit(&C,EVAL_MOFN);
|
||||
CMutableTransaction mtx; CPubKey mypk,Heirpk; CScript opret; struct CCcontract_info *cp,C;
|
||||
cp = CCinit(&C,EVAL_HEIR);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
mofnpk = GetUnspendable(cp,0);
|
||||
Heirpk = GetUnspendable(cp,0);
|
||||
if ( AddNormalinputs(mtx,mypk,funds+txfee,64) > 0 )
|
||||
{
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_MOFN,funds,mofnpk));
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_HEIR,funds,Heirpk));
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret));
|
||||
}
|
||||
return("");
|
||||
}
|
||||
|
||||
UniValue MofNInfo()
|
||||
UniValue HeirInfo()
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); char numstr[64];
|
||||
CMutableTransaction mtx; CPubKey mofnpk; struct CCcontract_info *cp,C; int64_t funding;
|
||||
CMutableTransaction mtx; CPubKey Heirpk; struct CCcontract_info *cp,C; int64_t funding;
|
||||
result.push_back(Pair("result","success"));
|
||||
result.push_back(Pair("name","MofN"));
|
||||
cp = CCinit(&C,EVAL_MOFN);
|
||||
mofnpk = GetUnspendable(cp,0);
|
||||
funding = AddMofNInputs(cp,mtx,mofnpk,0,0);
|
||||
result.push_back(Pair("name","Heir"));
|
||||
cp = CCinit(&C,EVAL_HEIR);
|
||||
Heirpk = GetUnspendable(cp,0);
|
||||
funding = AddHeirInputs(cp,mtx,Heirpk,0,0);
|
||||
sprintf(numstr,"%.8f",(double)funding/COIN);
|
||||
result.push_back(Pair("funding",numstr));
|
||||
return(result);
|
||||
@@ -162,6 +162,7 @@ bool LottoValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx)
|
||||
|
||||
int64_t AddLottoInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs)
|
||||
{
|
||||
// add threshold check
|
||||
char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector<uint8_t> origpubkey; CTransaction vintx; int32_t n = 0;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
GetCCaddress(cp,coinaddr,pk);
|
||||
@@ -291,10 +292,11 @@ std::string LottoCreate(uint64_t txfee,char *planstr,int64_t funding,int32_t tic
|
||||
sbits = stringbits(planstr);
|
||||
if ( AddNormalinputs(mtx,mypk,funding+txfee,60) > 0 )
|
||||
{
|
||||
hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash);
|
||||
hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n,1);
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_LOTTO,funding,lottopk));
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_LOTTO << (uint8_t)'F' << sbits << ticketsize << odds << firstheight << period << hentropy)));
|
||||
}
|
||||
return("");
|
||||
}
|
||||
|
||||
std::string LottoTicket(uint64_t txfee,uint256 lottoid,int64_t numtickets)
|
||||
|
||||
@@ -440,6 +440,7 @@ int64_t correlate_price(int32_t height,int64_t *prices,int32_t n)
|
||||
for (i=0; i<n; i++)
|
||||
fprintf(stderr,"%llu ",(long long)prices[i]);
|
||||
fprintf(stderr,"-> %llu ht.%d\n",(long long)price,height);
|
||||
return(price);
|
||||
}
|
||||
|
||||
int64_t OracleCorrelatedPrice(int32_t height,std::vector <int64_t> origprices)
|
||||
@@ -650,8 +651,12 @@ bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t
|
||||
}
|
||||
return eval->Invalid("unexpected OraclesValidate 'D' tx invalid");
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"illegal oracles funcid.(%c)\n",script[1]);
|
||||
return eval->Invalid("unexpected OraclesValidate funcid");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else return eval->Invalid("unexpected oracles missing funcid");
|
||||
return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts));
|
||||
}
|
||||
return(true);
|
||||
@@ -666,6 +671,7 @@ int64_t AddOracleInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
GetCCaddress(cp,coinaddr,pk);
|
||||
SetCCunspents(unspentOutputs,coinaddr);
|
||||
//fprintf(stderr,"addoracleinputs from (%s)\n",coinaddr);
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
@@ -804,7 +810,7 @@ std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector <uint8_t> da
|
||||
mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,batonpk));
|
||||
mtx.vout.push_back(CTxOut(datafee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeOraclesData('D',oracletxid,batontxid,mypk,data)));
|
||||
} else fprintf(stderr,"couldnt find enough oracle inputs, limit 1 per utxo\n");
|
||||
} else fprintf(stderr,"couldnt find enough oracle inputs %s, limit 1 per utxo\n",coinaddr);
|
||||
} else fprintf(stderr,"couldnt add normal inputs\n");
|
||||
return("");
|
||||
}
|
||||
@@ -853,11 +859,18 @@ UniValue OracleDataSamples(uint256 reforacletxid,uint256 batontxid,int32_t num)
|
||||
|
||||
UniValue OracleInfo(uint256 origtxid)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ),a(UniValue::VARR),obj(UniValue::VOBJ);
|
||||
UniValue result(UniValue::VOBJ),a(UniValue::VARR);
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
CMutableTransaction mtx; CTransaction regtx,tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid,batontxid; CPubKey pk; struct CCcontract_info *cp,C; int64_t datafee,funding; char str[67],markeraddr[64],numstr[64],batonaddr[64]; std::vector <uint8_t> data;
|
||||
cp = CCinit(&C,EVAL_ORACLES);
|
||||
CCtxidaddr(markeraddr,origtxid);
|
||||
if ( GetTransaction(origtxid,tx,hashBlock,false) == 0 )
|
||||
{
|
||||
fprintf(stderr,"cant find oracleid\n");
|
||||
result.push_back(Pair("result","error"));
|
||||
result.push_back(Pair("error","cant find oracleid"));
|
||||
return(result);
|
||||
}
|
||||
if ( GetTransaction(origtxid,tx,hashBlock,false) != 0 )
|
||||
{
|
||||
if ( tx.vout.size() > 0 && DecodeOraclesCreateOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,name,description,format) == 'C' )
|
||||
@@ -876,6 +889,7 @@ UniValue OracleInfo(uint256 origtxid)
|
||||
{
|
||||
if ( regtx.vout.size() > 0 && DecodeOraclesOpRet(regtx.vout[regtx.vout.size()-1].scriptPubKey,oracletxid,pk,datafee) == 'R' && oracletxid == origtxid )
|
||||
{
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.push_back(Pair("publisher",pubkey33_str(str,(uint8_t *)pk.begin())));
|
||||
Getscriptaddress(batonaddr,regtx.vout[1].scriptPubKey);
|
||||
batontxid = OracleBatonUtxo(10000,cp,oracletxid,batonaddr,pk,data);
|
||||
|
||||
@@ -115,6 +115,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &
|
||||
|
||||
int64_t AddPaymentsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs)
|
||||
{
|
||||
// add threshold check
|
||||
char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector<uint8_t> origpubkey; CTransaction vintx; int32_t vout,n = 0;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
GetCCaddress(cp,coinaddr,pk);
|
||||
|
||||
@@ -122,6 +122,7 @@ bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx)
|
||||
|
||||
int64_t AddPegsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs)
|
||||
{
|
||||
// add threshold check
|
||||
char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector<uint8_t> origpubkey; CTransaction vintx; int32_t vout,n = 0;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
GetCCaddress(cp,coinaddr,pk);
|
||||
|
||||
@@ -55,6 +55,8 @@
|
||||
|
||||
exposure address, funds address
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// start of consensus code
|
||||
@@ -127,6 +129,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx
|
||||
|
||||
int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char *destaddr,uint256 tolenid,int64_t total,int32_t maxinputs)
|
||||
{
|
||||
// add threshold check
|
||||
int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector<uint8_t> origpubkey; CTransaction vintx; int32_t vout,n = 0;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
SetCCunspents(unspentOutputs,destaddr);
|
||||
@@ -138,7 +141,7 @@ int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char
|
||||
if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && vout < vintx.vout.size() )
|
||||
{
|
||||
// need to verify assetid
|
||||
if ( (nValue= vintx.vout[vout].nValue) > 10000 && myIsutxo_spentinmempool(txid,vout) == 0 )
|
||||
if ( (nValue= vintx.vout[vout].nValue) >= 10000 && myIsutxo_spentinmempool(txid,vout) == 0 )
|
||||
{
|
||||
if ( total != 0 && maxinputs != 0 )
|
||||
mtx.vin.push_back(CTxIn(txid,vout,CScript()));
|
||||
@@ -179,7 +182,7 @@ UniValue PricesList()
|
||||
// bettoken
|
||||
std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletxid,uint64_t margin,uint64_t mode,uint256 longtoken,uint256 shorttoken,int32_t maxleverage,int64_t funding,std::vector<CPubKey> pubkeys)
|
||||
{
|
||||
CMutableTransaction mtx; CTransaction oracletx; int64_t fullsupply,inputs,CCchange=0; uint256 hashBlock; char str[65],coinaddr[64],houseaddr[64]; CPubKey mypk,pricespk; int32_t i,N,numvouts; struct CCcontract_info *cp,C,*assetscp,C2;
|
||||
CMutableTransaction mtx; CTransaction oracletx; int64_t fullsupply,inputs,CCchange=0; uint256 hashBlock; char str[65],coinaddr[64],houseaddr[64]; CPubKey mypk,pricespk; int32_t i,N,numvouts; struct CCcontract_info *cp,C;
|
||||
if ( funding < 100*COIN || maxleverage <= 0 || maxleverage > 10000 )
|
||||
{
|
||||
CCerror = "invalid parameter error";
|
||||
@@ -187,7 +190,6 @@ std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletx
|
||||
return("");
|
||||
}
|
||||
cp = CCinit(&C,EVAL_PRICES);
|
||||
assetscp = CCinit(&C2,EVAL_ASSETS);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
@@ -243,9 +245,8 @@ std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletx
|
||||
|
||||
UniValue PricesInfo(uint256 fundingtxid)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64],str[65]; std::vector<CPubKey>pubkeys; struct CCcontract_info *cp,C,*assetscp,C2;
|
||||
UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64],str[65]; std::vector<CPubKey>pubkeys; struct CCcontract_info *cp,C;
|
||||
cp = CCinit(&C,EVAL_PRICES);
|
||||
assetscp = CCinit(&C2,EVAL_ASSETS);
|
||||
pricespk = GetUnspendable(cp,0);
|
||||
if ( GetTransaction(fundingtxid,vintx,hashBlock,false) == 0 )
|
||||
{
|
||||
@@ -266,8 +267,8 @@ UniValue PricesInfo(uint256 fundingtxid)
|
||||
for (i=0; i<pubkeys.size(); i++)
|
||||
a.push_back(pubkey33_str(str,(uint8_t *)&pubkeys[i]));
|
||||
result.push_back(Pair("pubkeys",a));
|
||||
GetCCaddress1of2(assetscp,houseaddr,pricespk,planpk);
|
||||
GetCCaddress1of2(assetscp,exposureaddr,pricespk,pricespk); // assets addr
|
||||
GetCCaddress1of2(cp,houseaddr,pricespk,planpk);
|
||||
GetCCaddress1of2(cp,exposureaddr,pricespk,pricespk); // assets addr
|
||||
result.push_back(Pair("houseaddr",houseaddr));
|
||||
result.push_back(Pair("betaddr",exposureaddr));
|
||||
result.push_back(Pair("longtoken",uint256_str(str,longtoken)));
|
||||
@@ -292,7 +293,7 @@ UniValue PricesInfo(uint256 fundingtxid)
|
||||
|
||||
std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount)
|
||||
{
|
||||
CMutableTransaction mtx; struct CCcontract_info *cp,C,*assetscp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,CCchange = 0; uint64_t funding,mode; int32_t margin,maxleverage; char houseaddr[64],myaddr[64]; std::vector<CPubKey>pubkeys;
|
||||
CMutableTransaction mtx; struct CCcontract_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,CCchange = 0; uint64_t funding,mode; int32_t margin,maxleverage; char houseaddr[64],myaddr[64]; std::vector<CPubKey>pubkeys;
|
||||
if ( amount < 10000 )
|
||||
{
|
||||
CCerror = "amount must be positive";
|
||||
@@ -300,12 +301,11 @@ std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt
|
||||
return("");
|
||||
}
|
||||
cp = CCinit(&C,EVAL_PRICES);
|
||||
assetscp = CCinit(&C2,EVAL_ASSETS);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
pricespk = GetUnspendable(cp,0);
|
||||
GetCCaddress(assetscp,myaddr,mypk);
|
||||
GetCCaddress(cp,myaddr,mypk);
|
||||
if ( GetTransaction(fundingtxid,tx,hashBlock,false) == 0 )
|
||||
{
|
||||
fprintf(stderr,"cant find fundingtxid\n");
|
||||
@@ -313,16 +313,16 @@ std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt
|
||||
}
|
||||
if ( tx.vout.size() > 0 && DecodePricesFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' && bettoken == refbettoken )
|
||||
{
|
||||
GetCCaddress1of2(assetscp,houseaddr,pricespk,planpk);
|
||||
GetCCaddress1of2(cp,houseaddr,pricespk,planpk);
|
||||
if ( AddNormalinputs(mtx,mypk,2*txfee,3) > 0 )
|
||||
{
|
||||
if ( (inputs= AddTokensInputs(assetscp,mtx,myaddr,bettoken,amount,60)) >= amount )
|
||||
if ( (inputs= AddTokensInputs(cp,mtx,myaddr,bettoken,amount,60)) >= amount )
|
||||
{
|
||||
mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,amount,pricespk,planpk));
|
||||
mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,amount,pricespk,planpk));
|
||||
mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(planpk)) << OP_CHECKSIG));
|
||||
if ( inputs > amount+txfee )
|
||||
CCchange = (inputs - amount);
|
||||
mtx.vout.push_back(MakeCC1vout(assetscp->evalcode,CCchange,mypk));
|
||||
mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,mypk));
|
||||
// add addr2
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',bettoken,zeroid,0,Mypubkey())));
|
||||
}
|
||||
@@ -343,19 +343,18 @@ std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt
|
||||
|
||||
std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount,int32_t leverage)
|
||||
{
|
||||
CMutableTransaction mtx; struct CCcontract_info *cp,C,*assetscp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vector<CPubKey>pubkeys;
|
||||
CMutableTransaction mtx; struct CCcontract_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vector<CPubKey>pubkeys;
|
||||
if ( amount < 0 )
|
||||
{
|
||||
amount = -amount;
|
||||
dir = -1;
|
||||
} else dir = 1;
|
||||
cp = CCinit(&C,EVAL_PRICES);
|
||||
assetscp = CCinit(&C2,EVAL_ASSETS);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
pricespk = GetUnspendable(cp,0);
|
||||
GetCCaddress(assetscp,myaddr,mypk);
|
||||
GetCCaddress(cp,myaddr,mypk);
|
||||
if ( GetTransaction(fundingtxid,tx,hashBlock,false) == 0 )
|
||||
{
|
||||
fprintf(stderr,"cant find fundingtxid\n");
|
||||
@@ -368,8 +367,8 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int
|
||||
fprintf(stderr,"illegal leverage\n");
|
||||
return("");
|
||||
}
|
||||
GetCCaddress1of2(assetscp,houseaddr,pricespk,planpk);
|
||||
GetCCaddress1of2(assetscp,exposureaddr,pricespk,pricespk);
|
||||
GetCCaddress1of2(cp,houseaddr,pricespk,planpk);
|
||||
GetCCaddress1of2(cp,exposureaddr,pricespk,pricespk);
|
||||
if ( dir < 0 )
|
||||
tokenid = shorttoken;
|
||||
else tokenid = longtoken;
|
||||
@@ -387,22 +386,22 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int
|
||||
}
|
||||
if ( AddNormalinputs(mtx,mypk,txfee,3) > 0 )
|
||||
{
|
||||
if ( (inputs= AddTokensInputs(assetscp,mtx,houseaddr,tokenid,exposure,30)) >= exposure )
|
||||
if ( (inputs= AddTokensInputs(cp,mtx,houseaddr,tokenid,exposure,30)) >= exposure )
|
||||
{
|
||||
if ( (inputs2= AddTokensInputs(assetscp,mtx,myaddr,bettoken,amount,30)) >= amount )
|
||||
if ( (inputs2= AddTokensInputs(cp,mtx,myaddr,bettoken,amount,30)) >= amount )
|
||||
{
|
||||
mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,amount,pricespk,planpk));
|
||||
mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,exposure,pricespk,pricespk));
|
||||
mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,amount,pricespk,planpk));
|
||||
mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,exposure,pricespk,pricespk));
|
||||
if ( inputs > exposure+txfee )
|
||||
CCchange = (inputs - exposure);
|
||||
if ( inputs2 > amount+txfee )
|
||||
CCchange2 = (inputs2 - amount);
|
||||
mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,CCchange,pricespk,planpk));
|
||||
mtx.vout.push_back(MakeCC1vout(assetscp->evalcode,CCchange2,mypk));
|
||||
mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,CCchange,pricespk,planpk));
|
||||
mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange2,mypk));
|
||||
// add addr2 and addr3
|
||||
//return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,EncodePricesExtra('T',tokenid,bettoken,zeroid,dir*leverage)));
|
||||
//return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePricesExtra('T',tokenid,bettoken,zeroid,dir*leverage)));
|
||||
CScript opret;
|
||||
return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,opret));
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -287,8 +287,12 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t
|
||||
return eval->Invalid("unlock tx vout.2 isnt 0");
|
||||
preventCCvouts = 1;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"illegal rewards funcid.(%c)\n",funcid);
|
||||
return eval->Invalid("unexpected rewards funcid");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else return eval->Invalid("unexpected rewards missing funcid");
|
||||
return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts));
|
||||
}
|
||||
return(true);
|
||||
@@ -325,15 +329,16 @@ static uint64_t myIs_unlockedtx_inmempool(uint256 &txid,int32_t &vout,uint64_t r
|
||||
// 'L' vs 'F' and 'A'
|
||||
int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid)
|
||||
{
|
||||
char coinaddr[64],str[65]; uint64_t sbits,nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t numblocks,j,vout,n = 0; uint8_t funcid;
|
||||
char coinaddr[64],str[65]; uint64_t threshold,sbits,nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t numblocks,j,vout,n = 0; uint8_t funcid;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
GetCCaddress(cp,coinaddr,pk);
|
||||
SetCCunspents(unspentOutputs,coinaddr);
|
||||
threshold = total/maxinputs;
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
vout = (int32_t)it->first.index;
|
||||
if ( it->second.satoshis < 1000000 )
|
||||
if ( it->second.satoshis < threshold )
|
||||
continue;
|
||||
//fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN);
|
||||
for (j=0; j<mtx.vin.size(); j++)
|
||||
|
||||
@@ -114,6 +114,7 @@ bool TriggersValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &
|
||||
|
||||
int64_t AddTriggersInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs)
|
||||
{
|
||||
// add threshold check
|
||||
char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector<uint8_t> origpubkey; CTransaction vintx; int32_t vout,n = 0;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
GetCCaddress(cp,coinaddr,pk);
|
||||
|
||||
@@ -69,6 +69,7 @@ int CurrentEpoch(int nHeight, const Consensus::Params& params) {
|
||||
return idxInt;
|
||||
}
|
||||
}
|
||||
return(0); // jl777 seems the right value to return
|
||||
}
|
||||
|
||||
uint32_t CurrentEpochBranchId(int nHeight, const Consensus::Params& params) {
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#!/bin/bash
|
||||
./komodo-cli -ac_name=DION $1 $2 $3 $4 $5 $6
|
||||
#!/bin/bash
|
||||
./komodo-cli -ac_name=DION $1 $2 $3 $4 $5 $6
|
||||
|
||||
@@ -112,7 +112,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char
|
||||
errs++;
|
||||
if ( fread(&MoMdepth,1,sizeof(MoMdepth),fp) != sizeof(MoMdepth) )
|
||||
errs++;
|
||||
if ( 1 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 )
|
||||
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 )
|
||||
printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d CCid.%u\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth&0xffff,(MoMdepth>>16)&0xffff);
|
||||
}
|
||||
else
|
||||
@@ -257,7 +257,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long
|
||||
errs++;
|
||||
if ( memread(&MoMdepth,sizeof(MoMdepth),filedata,&fpos,datalen) != sizeof(MoMdepth) )
|
||||
errs++;
|
||||
if ( 1 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 )
|
||||
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 )
|
||||
printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d CCid.%u\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth&0xffff,(MoMdepth>>16)&0xffff);
|
||||
}
|
||||
else
|
||||
@@ -851,7 +851,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
printf("%02x",scriptPubKey[k]);
|
||||
printf(" scriptPubKey doesnt match any notary vini.%d of %d\n",j,numvins);
|
||||
}
|
||||
} else printf("cant get scriptPubKey for ht.%d txi.%d vin.%d\n",height,i,j);
|
||||
} //else printf("cant get scriptPubKey for ht.%d txi.%d vin.%d\n",height,i,j);
|
||||
}
|
||||
numvalid = bitweight(signedmask);
|
||||
if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) ||
|
||||
|
||||
@@ -391,7 +391,7 @@ int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heig
|
||||
{
|
||||
if ( (item= jobj(json,(char *)"result")) != 0 )
|
||||
{
|
||||
txid_confirmations = jint(item,(char *)"confirmations");
|
||||
txid_confirmations = jint(item,(char *)"rawconfirmations");
|
||||
if ( txid_confirmations > 0 && height > txid_confirmations )
|
||||
txid_height = height - txid_confirmations;
|
||||
else txid_height = height;
|
||||
@@ -1106,18 +1106,33 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_
|
||||
PoS stake must be without txfee and in the last tx in the block at vout[0]
|
||||
*/
|
||||
|
||||
uint64_t komodo_commission(const CBlock *pblock)
|
||||
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);
|
||||
|
||||
uint64_t komodo_commission(const CBlock *pblock,int32_t height)
|
||||
{
|
||||
int32_t i,j,n=0,txn_count; uint64_t commission,total = 0;
|
||||
int32_t i,j,n=0,txn_count; int64_t nSubsidy; uint64_t commission,total = 0;
|
||||
txn_count = pblock->vtx.size();
|
||||
for (i=0; i<txn_count; i++)
|
||||
if ( ASSETCHAINS_FOUNDERS != 0 )
|
||||
{
|
||||
n = pblock->vtx[i].vout.size();
|
||||
nSubsidy = GetBlockSubsidy(height,Params().GetConsensus());
|
||||
//fprintf(stderr,"ht.%d nSubsidy %.8f prod %llu\n",height,(double)nSubsidy/COIN,(long long)(nSubsidy * ASSETCHAINS_COMMISSION));
|
||||
return((nSubsidy * ASSETCHAINS_COMMISSION) / COIN);
|
||||
n = pblock->vtx[0].vout.size();
|
||||
for (j=0; j<n; j++)
|
||||
if ( j != 1 )
|
||||
total += pblock->vtx[0].vout[j].nValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=0; i<txn_count; i++)
|
||||
{
|
||||
//fprintf(stderr,"(%d %.8f).%d ",i,dstr(block.vtx[i].vout[j].nValue),j);
|
||||
if ( i != 0 || j != 1 )
|
||||
total += pblock->vtx[i].vout[j].nValue;
|
||||
n = pblock->vtx[i].vout.size();
|
||||
for (j=0; j<n; j++)
|
||||
{
|
||||
//fprintf(stderr,"(%d %.8f).%d ",i,dstr(block.vtx[i].vout[j].nValue),j);
|
||||
if ( i != 0 || j != 1 )
|
||||
total += pblock->vtx[i].vout[j].nValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
//fprintf(stderr,"txn.%d n.%d commission total %.8f -> %.8f\n",txn_count,n,dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN));
|
||||
@@ -1164,7 +1179,7 @@ int8_t komodo_segid(int32_t nocache,int32_t height)
|
||||
return(segid);
|
||||
}
|
||||
|
||||
int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n)
|
||||
void komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n)
|
||||
{
|
||||
static uint8_t prevhashbuf[100]; static int32_t prevheight;
|
||||
int32_t i;
|
||||
@@ -1284,7 +1299,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh
|
||||
|
||||
arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc)
|
||||
{
|
||||
int32_t oldflag = 0;
|
||||
int32_t oldflag = 0,dispflag = 0;
|
||||
CBlockIndex *pindex; arith_uint256 easydiff,bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,m,ht,percPoS,diff,val;
|
||||
*percPoSp = percPoS = 0;
|
||||
if ( height <= 10 || (ASSETCHAINS_STAKED == 100 && height <= 100) )
|
||||
@@ -1303,23 +1318,23 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he
|
||||
{
|
||||
n++;
|
||||
percPoS++;
|
||||
if ( ASSETCHAINS_STAKED < 100 )
|
||||
if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 )
|
||||
fprintf(stderr,"0");
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ASSETCHAINS_STAKED < 100 )
|
||||
if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 )
|
||||
fprintf(stderr,"1");
|
||||
sum += UintToArith256(pindex->GetBlockHash());
|
||||
m++;
|
||||
}
|
||||
}
|
||||
if ( ASSETCHAINS_STAKED < 100 && (i % 10) == 9 )
|
||||
if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 && (i % 10) == 9 )
|
||||
fprintf(stderr," %d, ",percPoS);
|
||||
}
|
||||
if ( m+n < 100 )
|
||||
percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100;
|
||||
if ( ASSETCHAINS_STAKED < 100 )
|
||||
if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 )
|
||||
fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height);
|
||||
*percPoSp = percPoS;
|
||||
if ( m > 0 )
|
||||
@@ -1332,12 +1347,10 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he
|
||||
percPoS = 1;
|
||||
if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget
|
||||
{
|
||||
//if ( oldflag != 0 )
|
||||
// bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256(goalperc * goalperc * goalperc);
|
||||
if ( oldflag != 0 )
|
||||
bnTarget = (ave / arith_uint256(goalperc * goalperc * goalperc)) * arith_uint256(percPoS * percPoS);
|
||||
else bnTarget = (ave / arith_uint256(goalperc * goalperc * goalperc * goalperc)) * arith_uint256(percPoS * percPoS);
|
||||
if ( ASSETCHAINS_STAKED < 100 )
|
||||
if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 )
|
||||
{
|
||||
for (i=31; i>=24; i--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&ave)[i]);
|
||||
@@ -1355,7 +1368,6 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he
|
||||
if ( oldflag != 0 )
|
||||
{
|
||||
bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc);
|
||||
//bnTarget = (bnTarget * arith_uint256(percPoS * percPoS * percPoS)) / arith_uint256(goalperc * goalperc);
|
||||
bnTarget = (bnTarget / arith_uint256(goalperc * goalperc)) * arith_uint256(percPoS * percPoS * percPoS);
|
||||
}
|
||||
else bnTarget = (ave / arith_uint256(goalperc * goalperc)) * arith_uint256(percPoS * percPoS * percPoS);
|
||||
@@ -1367,7 +1379,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he
|
||||
if ( bnTarget < ave )
|
||||
bnTarget = ave;
|
||||
}
|
||||
if ( 1 )
|
||||
if ( dispflag != 0 )
|
||||
{
|
||||
for (i=31; i>=24; i--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&ave)[i]);
|
||||
@@ -1453,7 +1465,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_
|
||||
bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED);
|
||||
if ( bhash < bnTarget )
|
||||
{
|
||||
fprintf(stderr,"ht.%d isPoS but meets PoW diff!\n",height);
|
||||
//fprintf(stderr,"ht.%d isPoS but meets PoW diff!\n",height);
|
||||
isPoS = 0;
|
||||
}
|
||||
}
|
||||
@@ -1466,17 +1478,39 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_
|
||||
|
||||
int64_t komodo_checkcommission(CBlock *pblock,int32_t height)
|
||||
{
|
||||
int64_t checktoshis=0; uint8_t *script;
|
||||
int64_t checktoshis=0; uint8_t *script,scripthex[8192]; int32_t scriptlen,matched = 0;
|
||||
if ( ASSETCHAINS_COMMISSION != 0 )
|
||||
{
|
||||
checktoshis = komodo_commission(pblock);
|
||||
if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 )
|
||||
checktoshis = komodo_commission(pblock,height);
|
||||
//fprintf(stderr,"height.%d commission %.8f\n",height,(double)checktoshis/COIN);
|
||||
/*if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 ) jl777: not sure why this was here
|
||||
return(-1);
|
||||
else if ( checktoshis != 0 )
|
||||
else*/ if ( checktoshis != 0 )
|
||||
{
|
||||
script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data();
|
||||
if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 )
|
||||
scriptlen = (int32_t)pblock->vtx[0].vout[1].scriptPubKey.size();
|
||||
if ( ASSETCHAINS_SCRIPTPUB.size() > 1 )
|
||||
{
|
||||
if ( ASSETCHAINS_SCRIPTPUB.size()/2 == scriptlen && scriptlen < sizeof(scripthex) )
|
||||
{
|
||||
decode_hex(scripthex,scriptlen,(char *)ASSETCHAINS_SCRIPTPUB.c_str());
|
||||
if ( memcmp(scripthex,script,scriptlen) == 0 )
|
||||
matched = scriptlen;
|
||||
}
|
||||
}
|
||||
else if ( scriptlen == 35 && script[0] == 33 && script[34] == OP_CHECKSIG && memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) == 0 )
|
||||
matched = 35;
|
||||
else if ( scriptlen == 25 && script[0] == OP_DUP && script[1] == OP_HASH160 && script[2] == 20 && script[23] == OP_EQUALVERIFY && script[24] == OP_CHECKSIG && memcmp(script+3,ASSETCHAINS_OVERRIDE_PUBKEYHASH,20) == 0 )
|
||||
matched = 25;
|
||||
if ( matched == 0 )
|
||||
{
|
||||
int32_t i;
|
||||
for (i=0; i<25; i++)
|
||||
fprintf(stderr,"%02x",script[i]);
|
||||
fprintf(stderr," payment to wrong pubkey scriptlen.%d, scriptpub[%d]\n",scriptlen,(int32_t)ASSETCHAINS_SCRIPTPUB.size()/2);
|
||||
return(-1);
|
||||
|
||||
}
|
||||
if ( pblock->vtx[0].vout[1].nValue != checktoshis )
|
||||
{
|
||||
fprintf(stderr,"ht.%d checktoshis %.8f vs actual vout[1] %.8f\n",height,dstr(checktoshis),dstr(pblock->vtx[0].vout[1].nValue));
|
||||
|
||||
@@ -9,5 +9,8 @@
|
||||
#define IGUANA_MAXSCRIPTSIZE 10001
|
||||
#define KOMODO_MAXMEMPOOLTIME 3600 // affects consensus
|
||||
#define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9"
|
||||
#define KOMODO_FIRSTFUNGIBLEID 100
|
||||
|
||||
extern uint8_t ASSETCHAINS_TXPOW;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1380,8 +1380,9 @@ void komodo_passport_iteration()
|
||||
}
|
||||
if ( komodo_chainactive_timestamp() > lastinterest )
|
||||
{
|
||||
komodo_interestsum();
|
||||
komodo_longestchain();
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||
komodo_interestsum();
|
||||
//komodo_longestchain();
|
||||
lastinterest = komodo_chainactive_timestamp();
|
||||
}
|
||||
refsp = komodo_stateptr(symbol,dest);
|
||||
|
||||
@@ -45,20 +45,20 @@ struct komodo_state KOMODO_STATES[34];
|
||||
#define _COINBASE_MATURITY 100
|
||||
int COINBASE_MATURITY = _COINBASE_MATURITY;//100;
|
||||
|
||||
int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1;
|
||||
int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE;
|
||||
int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1;
|
||||
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY;
|
||||
uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE;
|
||||
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB;
|
||||
uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_FOUNDERS;
|
||||
|
||||
char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096];
|
||||
uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;
|
||||
uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT;
|
||||
uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT,KOMODO_DPOWCONFS = 1;
|
||||
uint32_t ASSETCHAINS_MAGIC = 2387029918;
|
||||
uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE;
|
||||
uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10;
|
||||
|
||||
uint32_t KOMODO_INITDONE;
|
||||
char KMDUSERPASS[8192],BTCUSERPASS[8192]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771;
|
||||
char KMDUSERPASS[8192+512+1],BTCUSERPASS[8192]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771;
|
||||
uint64_t PENDING_KOMODO_TX;
|
||||
extern int32_t KOMODO_LOADINGBLOCKS;
|
||||
unsigned int MAX_BLOCK_SIGOPS = 20000;
|
||||
|
||||
@@ -117,7 +117,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value)
|
||||
}
|
||||
valueptr = &key[keylen];
|
||||
fee = komodo_kvfee(flags,opretlen,keylen);
|
||||
//printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]);
|
||||
//fprintf(stderr,"fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]);
|
||||
if ( value >= fee )
|
||||
{
|
||||
coresize = (int32_t)(sizeof(flags)+sizeof(height)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1);
|
||||
|
||||
@@ -452,6 +452,21 @@ int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *
|
||||
}
|
||||
}
|
||||
|
||||
int32_t komodo_dpowconfs(int32_t txheight,int32_t numconfs)
|
||||
{
|
||||
char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
|
||||
if ( KOMODO_DPOWCONFS != 0 && txheight > 0 && numconfs > 0 && (sp= komodo_stateptr(symbol,dest)) != 0 )
|
||||
{
|
||||
if ( sp->NOTARIZED_HEIGHT > 0 )
|
||||
{
|
||||
if ( txheight < sp->NOTARIZED_HEIGHT )
|
||||
return(numconfs);
|
||||
else return(1);
|
||||
}
|
||||
}
|
||||
return(numconfs);
|
||||
}
|
||||
|
||||
int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t height,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip)
|
||||
{
|
||||
struct notarized_checkpoint *np = 0;
|
||||
|
||||
@@ -1503,7 +1503,7 @@ void komodo_args(char *argv0)
|
||||
{
|
||||
extern int64_t MAX_MONEY;
|
||||
extern const char *Notaries_elected1[][2];
|
||||
std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[256],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,baseid,len,n,extralen = 0;
|
||||
std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[8192],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,baseid,len,n,extralen = 0;
|
||||
IS_KOMODO_NOTARY = GetBoolArg("-notary", false);
|
||||
if ( GetBoolArg("-gen", false) != 0 )
|
||||
KOMODO_MININGTHREADS = GetArg("-genproclimit",1);
|
||||
@@ -1512,6 +1512,7 @@ void komodo_args(char *argv0)
|
||||
fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n");
|
||||
DONATION_PUBKEY = GetArg("-donation", "");
|
||||
NOTARY_PUBKEY = GetArg("-pubkey", "");
|
||||
KOMODO_DEALERNODE = GetArg("-dealer",0);
|
||||
if ( strlen(NOTARY_PUBKEY.c_str()) == 66 )
|
||||
{
|
||||
USE_EXTERNAL_PUBKEY = 1;
|
||||
@@ -1554,6 +1555,8 @@ void komodo_args(char *argv0)
|
||||
if ( name.c_str()[0] != 0 )
|
||||
{
|
||||
MAX_BLOCK_SIGOPS = 60000;
|
||||
ASSETCHAINS_TXPOW = GetArg("-ac_txpow",0) & 3;
|
||||
ASSETCHAINS_FOUNDERS = GetArg("-ac_founders",0) & 1;
|
||||
ASSETCHAINS_SUPPLY = GetArg("-ac_supply",10);
|
||||
ASSETCHAINS_ENDSUBSIDY = GetArg("-ac_end",0);
|
||||
ASSETCHAINS_REWARD = GetArg("-ac_reward",0);
|
||||
@@ -1561,6 +1564,7 @@ void komodo_args(char *argv0)
|
||||
ASSETCHAINS_DECAY = GetArg("-ac_decay",0);
|
||||
ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0);
|
||||
ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey","");
|
||||
ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script","");
|
||||
if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 )
|
||||
ASSETCHAINS_STAKED = 100;
|
||||
if ( ASSETCHAINS_STAKED != 0 && ASSETCHAINS_PRIVATE != 0 )
|
||||
@@ -1583,14 +1587,33 @@ void komodo_args(char *argv0)
|
||||
ASSETCHAINS_DECAY = 0;
|
||||
printf("ASSETCHAINS_DECAY cant be more than 100000000\n");
|
||||
}
|
||||
if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 )
|
||||
decode_hex(ASSETCHAINS_OVERRIDE_PUBKEY33,33,(char *)ASSETCHAINS_OVERRIDE_PUBKEY.c_str());
|
||||
else if ( ASSETCHAINS_COMMISSION != 0 )
|
||||
if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 || ASSETCHAINS_SCRIPTPUB.size() > 1 )
|
||||
{
|
||||
ASSETCHAINS_COMMISSION = 0;
|
||||
printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY and cant be more than 100000000 (100%%)\n");
|
||||
if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 )
|
||||
{
|
||||
decode_hex(ASSETCHAINS_OVERRIDE_PUBKEY33,33,(char *)ASSETCHAINS_OVERRIDE_PUBKEY.c_str());
|
||||
calc_rmd160_sha256(ASSETCHAINS_OVERRIDE_PUBKEYHASH,ASSETCHAINS_OVERRIDE_PUBKEY33,33);
|
||||
}
|
||||
if ( ASSETCHAINS_COMMISSION == 0 && ASSETCHAINS_FOUNDERS != 0 )
|
||||
{
|
||||
ASSETCHAINS_COMMISSION = 53846154; // maps to 35%
|
||||
printf("ASSETCHAINS_COMMISSION defaulted to 35%% when founders reward active\n");
|
||||
}
|
||||
}
|
||||
if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 )
|
||||
else
|
||||
{
|
||||
if ( ASSETCHAINS_COMMISSION != 0 )
|
||||
{
|
||||
ASSETCHAINS_COMMISSION = 0;
|
||||
printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY and cant be more than 100000000 (100%%)\n");
|
||||
}
|
||||
if ( ASSETCHAINS_FOUNDERS != 0 )
|
||||
{
|
||||
ASSETCHAINS_FOUNDERS = 0;
|
||||
printf("ASSETCHAINS_FOUNDERS needs an ASETCHAINS_OVERRIDE_PUBKEY\n");
|
||||
}
|
||||
}
|
||||
if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 )
|
||||
{
|
||||
fprintf(stderr,"end.%llu blocks, reward %.8f halving.%llu blocks, decay.%llu perc %.4f%% ac_pub=[%02x...]\n",(long long)ASSETCHAINS_ENDSUBSIDY,dstr(ASSETCHAINS_REWARD),(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0]);
|
||||
extraptr = extrabuf;
|
||||
@@ -1599,8 +1622,12 @@ void komodo_args(char *argv0)
|
||||
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_REWARD),(void *)&ASSETCHAINS_REWARD);
|
||||
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_HALVING),(void *)&ASSETCHAINS_HALVING);
|
||||
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_DECAY),(void *)&ASSETCHAINS_DECAY);
|
||||
val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6);
|
||||
val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW;
|
||||
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val);
|
||||
if ( ASSETCHAINS_FOUNDERS != 0 )
|
||||
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS),(void *)&ASSETCHAINS_FOUNDERS);
|
||||
if ( ASSETCHAINS_SCRIPTPUB.size() > 1 )
|
||||
extralen += iguana_rwnum(1,&extraptr[extralen],(int32_t)ASSETCHAINS_SCRIPTPUB.size(),(void *)ASSETCHAINS_SCRIPTPUB.c_str());
|
||||
}
|
||||
addn = GetArg("-seednode","");
|
||||
if ( strlen(addn.c_str()) > 0 )
|
||||
@@ -1612,6 +1639,11 @@ void komodo_args(char *argv0)
|
||||
MAX_MONEY = (ASSETCHAINS_SUPPLY+100) * SATOSHIDEN;
|
||||
else MAX_MONEY = (ASSETCHAINS_SUPPLY+100) * SATOSHIDEN + ASSETCHAINS_REWARD * (ASSETCHAINS_ENDSUBSIDY==0 ? 10000000 : ASSETCHAINS_ENDSUBSIDY);
|
||||
MAX_MONEY += (MAX_MONEY * ASSETCHAINS_COMMISSION) / SATOSHIDEN;
|
||||
if ( ASSETCHAINS_CC >= KOMODO_FIRSTFUNGIBLEID && MAX_MONEY < 1000000LL*SATOSHIDEN )
|
||||
MAX_MONEY = 1000000LL*SATOSHIDEN;
|
||||
if ( MAX_MONEY <= 0 || MAX_MONEY > 10000100000LL*SATOSHIDEN )
|
||||
MAX_MONEY = 10000100000LL*SATOSHIDEN;
|
||||
//fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN);
|
||||
//printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN);
|
||||
ASSETCHAINS_P2PPORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen);
|
||||
while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 )
|
||||
@@ -1700,6 +1732,7 @@ void komodo_args(char *argv0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
int32_t dpowconfs = KOMODO_DPOWCONFS;
|
||||
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
{
|
||||
BITCOIND_RPCPORT = GetArg("-rpcport", ASSETCHAINS_RPCPORT);
|
||||
@@ -1709,7 +1742,10 @@ void komodo_args(char *argv0)
|
||||
ASSETCHAINS_HALVING *= 5;
|
||||
fprintf(stderr,"PIRATE halving changed to %d %.1f days\n",(int32_t)ASSETCHAINS_HALVING,(double)ASSETCHAINS_HALVING/1440);
|
||||
}
|
||||
else if ( strcmp("VRSC",ASSETCHAINS_SYMBOL) == 0 )
|
||||
dpowconfs = 0;
|
||||
} else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort());
|
||||
KOMODO_DPOWCONFS = GetArg("-dpowconfs",dpowconfs);
|
||||
}
|
||||
|
||||
void komodo_nameset(char *symbol,char *dest,char *source)
|
||||
|
||||
1188
src/main.cpp
1188
src/main.cpp
File diff suppressed because it is too large
Load Diff
18
src/main.h
18
src/main.h
@@ -180,11 +180,11 @@ void RegisterNodeSignals(CNodeSignals& nodeSignals);
|
||||
/** Unregister a network node */
|
||||
void UnregisterNodeSignals(CNodeSignals& nodeSignals);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Process an incoming block. This only returns after the best known valid
|
||||
* block is made active. Note that it does not, however, guarantee that the
|
||||
* specific block passed to it has been checked for validity!
|
||||
*
|
||||
*
|
||||
* @param[out] state This may be set to an Error state if any error occurred processing it, including during validation/connection/etc of otherwise unrelated blocks during reorganisation; or it may be set to an Invalid state if pblock is itself invalid (but this is not guaranteed even when the block is checked). If you want to *possibly* get feedback on whether pblock is valid, you must also install a CValidationInterface (see validationinterface.h) - this will have its BlockChecked method called whenever *any* block completes validation.
|
||||
* @param[in] pfrom The node which we are receiving the block from; it is added to mapBlockSource and may be penalised if the block is invalid.
|
||||
* @param[in] pblock The block we want to process.
|
||||
@@ -640,7 +640,7 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF
|
||||
/**
|
||||
* Check transaction inputs, and make sure any
|
||||
* pay-to-script-hash transactions are evaluating IsStandard scripts
|
||||
*
|
||||
*
|
||||
* Why bother? To avoid denial-of-service attacks; an attacker
|
||||
* can submit a standard HASH... OP_EQUAL transaction,
|
||||
* which will get accepted into blocks. The redemption
|
||||
@@ -649,14 +649,14 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF
|
||||
* DUP CHECKSIG DROP ... repeated 100 times... OP_1
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Check for standard transaction types
|
||||
* @param[in] mapInputs Map of previous transactions that have outputs we're spending
|
||||
* @return True if all inputs (scriptSigs) use only standard transaction forms
|
||||
*/
|
||||
bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, uint32_t consensusBranchId);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Count ECDSA signature operations the old-fashioned (pre-0.6) way
|
||||
* @return number of sigops this transaction's outputs will produce when spent
|
||||
* @see CTransaction::FetchInputs
|
||||
@@ -665,7 +665,7 @@ unsigned int GetLegacySigOpCount(const CTransaction& tx);
|
||||
|
||||
/**
|
||||
* Count ECDSA signature operations in pay-to-script-hash inputs.
|
||||
*
|
||||
*
|
||||
* @param[in] mapInputs Map of previous transactions that have outputs we're spending
|
||||
* @return maximum number of sigops required to validate this transaction's inputs
|
||||
* @see CTransaction::FetchInputs
|
||||
@@ -732,9 +732,9 @@ bool IsExpiredTx(const CTransaction &tx, int nBlockHeight);
|
||||
*/
|
||||
bool CheckFinalTx(const CTransaction &tx, int flags = -1);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Closure representing one script verification
|
||||
* Note that this stores references to the spending transaction
|
||||
* Note that this stores references to the spending transaction
|
||||
*/
|
||||
class CScriptCheck
|
||||
{
|
||||
@@ -916,6 +916,8 @@ extern CBlockTreeDB *pblocktree;
|
||||
*/
|
||||
int GetSpendHeight(const CCoinsViewCache& inputs);
|
||||
|
||||
uint64_t CalculateCurrentUsage();
|
||||
|
||||
/** Return a CMutableTransaction with contextual default values based on set of consensus rules at height */
|
||||
CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight);
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams,
|
||||
extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE;
|
||||
extern uint64_t ASSETCHAINS_REWARD,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED;
|
||||
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
||||
extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY;
|
||||
extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY,ASSETCHAINS_SCRIPTPUB;
|
||||
void vcalc_sha256(char deprecated[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len);
|
||||
|
||||
extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33];
|
||||
@@ -119,7 +119,7 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,
|
||||
int32_t komodo_pax_opreturn(int32_t height,uint8_t *opret,int32_t maxsize);
|
||||
int32_t komodo_baseid(char *origbase);
|
||||
int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag);
|
||||
uint64_t komodo_commission(const CBlock *block);
|
||||
uint64_t komodo_commission(const CBlock *block,int32_t height);
|
||||
int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig);
|
||||
int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33);
|
||||
|
||||
@@ -335,6 +335,16 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
//fprintf(stderr,"dont have inputs\n");
|
||||
continue;
|
||||
}
|
||||
if ( 0 )
|
||||
{
|
||||
CValidationState state;
|
||||
auto verifier = libzcash::ProofVerifier::Disabled();
|
||||
if ( !CheckTransaction(tx, state, verifier) )
|
||||
{
|
||||
fprintf(stderr,"skip tx.(%s) that failed CheckTransaction\n",hash.GetHex().c_str());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime)-tx.GetValueOut();
|
||||
|
||||
nTxSigOps += GetP2SHSigOpCount(tx, view);
|
||||
@@ -428,17 +438,22 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
txNew.vin[0].scriptSig = CScript() << nHeight << OP_0;
|
||||
|
||||
pblock->vtx[0] = txNew;
|
||||
if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block)) != 0 )
|
||||
if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0 )
|
||||
{
|
||||
int32_t i; uint8_t *ptr;
|
||||
txNew.vout.resize(2);
|
||||
txNew.vout[1].nValue = commission;
|
||||
txNew.vout[1].scriptPubKey.resize(35);
|
||||
ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data();
|
||||
ptr[0] = 33;
|
||||
for (i=0; i<33; i++)
|
||||
ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i];
|
||||
ptr[34] = OP_CHECKSIG;
|
||||
if ( ASSETCHAINS_SCRIPTPUB.size() > 1 )
|
||||
txNew.vout[1].scriptPubKey = CScript() << ParseHex(ASSETCHAINS_SCRIPTPUB);
|
||||
else
|
||||
{
|
||||
txNew.vout[1].scriptPubKey.resize(35);
|
||||
ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data();
|
||||
ptr[0] = 33;
|
||||
for (i=0; i<33; i++)
|
||||
ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i];
|
||||
ptr[34] = OP_CHECKSIG;
|
||||
}
|
||||
//printf("autocreate commision vout\n");
|
||||
pblock->vtx[0] = txNew;
|
||||
}
|
||||
@@ -739,7 +754,7 @@ void static BitcoinMiner()
|
||||
|
||||
unsigned int n = chainparams.EquihashN();
|
||||
unsigned int k = chainparams.EquihashK();
|
||||
uint8_t *script; uint64_t total,checktoshis; int32_t i,j,gpucount=KOMODO_MAXGPUCOUNT,notaryid = -1;
|
||||
uint8_t *script; uint64_t total; int32_t i,j,gpucount=KOMODO_MAXGPUCOUNT,notaryid = -1;
|
||||
while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) )
|
||||
{
|
||||
sleep(1);
|
||||
@@ -930,7 +945,7 @@ void static BitcoinMiner()
|
||||
{
|
||||
fprintf(stderr,"Mining when blockchain might not be in sync longest.%d vs %d\n",KOMODO_LONGESTCHAIN,Mining_height);
|
||||
if ( KOMODO_LONGESTCHAIN != 0 && Mining_height >= KOMODO_LONGESTCHAIN )
|
||||
KOMODO_INSYNC = 1;
|
||||
KOMODO_INSYNC = Mining_height;
|
||||
sleep(3);
|
||||
}
|
||||
// Hash state
|
||||
|
||||
@@ -32,6 +32,8 @@ using namespace std;
|
||||
extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry);
|
||||
void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
|
||||
int32_t komodo_longestchain();
|
||||
int32_t komodo_dpowconfs(int32_t height,int32_t numconfs);
|
||||
extern int32_t KOMODO_LONGESTCHAIN;
|
||||
|
||||
double GetDifficultyINTERNAL(const CBlockIndex* blockindex, bool networkDifficulty)
|
||||
{
|
||||
@@ -117,7 +119,8 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex)
|
||||
// Only report confirmations if the block is on the main chain
|
||||
if (chainActive.Contains(blockindex))
|
||||
confirmations = chainActive.Height() - blockindex->nHeight + 1;
|
||||
result.push_back(Pair("confirmations", confirmations));
|
||||
result.push_back(Pair("confirmations", komodo_dpowconfs(blockindex->nHeight,confirmations)));
|
||||
result.push_back(Pair("rawconfirmations", confirmations));
|
||||
result.push_back(Pair("height", blockindex->nHeight));
|
||||
result.push_back(Pair("version", blockindex->nVersion));
|
||||
result.push_back(Pair("merkleroot", blockindex->hashMerkleRoot.GetHex()));
|
||||
@@ -148,7 +151,8 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex)
|
||||
} else {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block is an orphan");
|
||||
}
|
||||
result.push_back(Pair("confirmations", confirmations));
|
||||
result.push_back(Pair("confirmations", komodo_dpowconfs(blockindex->nHeight,confirmations)));
|
||||
result.push_back(Pair("rawconfirmations", confirmations));
|
||||
result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)));
|
||||
result.push_back(Pair("height", blockindex->nHeight));
|
||||
result.push_back(Pair("version", block.nVersion));
|
||||
@@ -265,7 +269,8 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
|
||||
// Only report confirmations if the block is on the main chain
|
||||
if (chainActive.Contains(blockindex))
|
||||
confirmations = chainActive.Height() - blockindex->nHeight + 1;
|
||||
result.push_back(Pair("confirmations", confirmations));
|
||||
result.push_back(Pair("confirmations", komodo_dpowconfs(blockindex->nHeight,confirmations)));
|
||||
result.push_back(Pair("rawconfirmations", confirmations));
|
||||
result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)));
|
||||
result.push_back(Pair("height", blockindex->nHeight));
|
||||
result.push_back(Pair("version", block.nVersion));
|
||||
@@ -374,6 +379,18 @@ bool myIsutxo_spentinmempool(uint256 txid,int32_t vout)
|
||||
return(false);
|
||||
}
|
||||
|
||||
bool mytxid_inmempool(uint256 txid)
|
||||
{
|
||||
BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx)
|
||||
{
|
||||
const CTransaction &tx = e.GetTx();
|
||||
const uint256 &hash = tx.GetHash();
|
||||
if ( txid == hash )
|
||||
return(true);
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
|
||||
UniValue mempoolToJSON(bool fVerbose = false)
|
||||
{
|
||||
if (fVerbose)
|
||||
@@ -1150,7 +1167,11 @@ UniValue gettxout(const UniValue& params, bool fHelp)
|
||||
ret.push_back(Pair("bestblock", pindex->GetBlockHash().GetHex()));
|
||||
if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT)
|
||||
ret.push_back(Pair("confirmations", 0));
|
||||
else ret.push_back(Pair("confirmations", pindex->nHeight - coins.nHeight + 1));
|
||||
else
|
||||
{
|
||||
ret.push_back(Pair("confirmations", komodo_dpowconfs(coins.nHeight,pindex->nHeight - coins.nHeight + 1)));
|
||||
ret.push_back(Pair("rawconfirmations", pindex->nHeight - coins.nHeight + 1));
|
||||
}
|
||||
ret.push_back(Pair("value", ValueFromAmount(coins.vout[n].nValue)));
|
||||
uint64_t interest; int32_t txheight; uint32_t locktime;
|
||||
if ( (interest= komodo_accrued_interest(&txheight,&locktime,hash,n,coins.nHeight,coins.vout[n].nValue,(int32_t)pindex->nHeight)) != 0 )
|
||||
@@ -1253,6 +1274,7 @@ void NetworkUpgradeDescPushBack(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
UniValue getblockchaininfo(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
@@ -1270,6 +1292,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
|
||||
" \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
|
||||
" \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n"
|
||||
" \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n"
|
||||
" \"size_on_disk\": xxxxxx, (numeric) the estimated size of the block and undo files on disk\n"
|
||||
" \"commitments\": xxxxxx, (numeric) the current number of note commitments in the commitment tree\n"
|
||||
" \"softforks\": [ (array) status of softforks in progress\n"
|
||||
" {\n"
|
||||
@@ -1307,7 +1330,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 ) {
|
||||
progress = Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.LastTip());
|
||||
} else {
|
||||
int32_t longestchain = komodo_longestchain();
|
||||
int32_t longestchain = KOMODO_LONGESTCHAIN;//komodo_longestchain();
|
||||
progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 1.0;
|
||||
}
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
@@ -1319,6 +1342,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
|
||||
obj.push_back(Pair("verificationprogress", progress));
|
||||
obj.push_back(Pair("chainwork", chainActive.LastTip()->nChainWork.GetHex()));
|
||||
obj.push_back(Pair("pruned", fPruneMode));
|
||||
obj.push_back(Pair("size_on_disk", CalculateCurrentUsage()));
|
||||
|
||||
ZCIncrementalMerkleTree tree;
|
||||
pcoinsTip->GetAnchorAt(pcoinsTip->GetBestAnchor(), tree);
|
||||
|
||||
@@ -50,7 +50,9 @@ UniValue assetchainproof(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue crosschainproof(const UniValue& params, bool fHelp)
|
||||
{
|
||||
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
//fprintf(stderr,"crosschainproof needs to be implemented\n");
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;
|
||||
extern uint32_t ASSETCHAINS_CC;
|
||||
extern uint32_t ASSETCHAINS_MAGIC;
|
||||
extern uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY;
|
||||
extern std::string NOTARY_PUBKEY; extern uint8_t NOTARY_PUBKEY33[];
|
||||
|
||||
UniValue getinfo(const UniValue& params, bool fHelp)
|
||||
{
|
||||
@@ -121,9 +122,15 @@ UniValue getinfo(const UniValue& params, bool fHelp)
|
||||
#ifdef ENABLE_WALLET
|
||||
if (pwalletMain) {
|
||||
obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
|
||||
obj.push_back(Pair("balance", ValueFromAmount(KOMODO_WALLETBALANCE))); //pwalletMain->GetBalance()
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||
obj.push_back(Pair("interest", ValueFromAmount(KOMODO_INTERESTSUM))); //komodo_interestsum()
|
||||
{
|
||||
obj.push_back(Pair("interest", ValueFromAmount(KOMODO_INTERESTSUM)));
|
||||
obj.push_back(Pair("balance", ValueFromAmount(KOMODO_WALLETBALANCE))); //pwalletMain->GetBalance()
|
||||
}
|
||||
else
|
||||
{
|
||||
obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance()))); //
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//fprintf(stderr,"after wallet %u\n",(uint32_t)time(NULL));
|
||||
@@ -158,16 +165,18 @@ UniValue getinfo(const UniValue& params, bool fHelp)
|
||||
obj.push_back(Pair("pubkey", pubkeystr));
|
||||
if ( KOMODO_LASTMINED != 0 )
|
||||
obj.push_back(Pair("lastmined", KOMODO_LASTMINED));
|
||||
} else if ( NOTARY_PUBKEY33[0] != 0 ) {
|
||||
obj.push_back(Pair("pubkey", NOTARY_PUBKEY));
|
||||
}
|
||||
}
|
||||
if ( ASSETCHAINS_CC != 0 )
|
||||
obj.push_back(Pair("CCid", (int)ASSETCHAINS_CC));
|
||||
obj.push_back(Pair("name", ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL));
|
||||
obj.push_back(Pair("p2pport", ASSETCHAINS_P2PPORT));
|
||||
obj.push_back(Pair("rpcport", ASSETCHAINS_RPCPORT));
|
||||
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
{
|
||||
//obj.push_back(Pair("name", ASSETCHAINS_SYMBOL));
|
||||
obj.push_back(Pair("p2pport", ASSETCHAINS_P2PPORT));
|
||||
obj.push_back(Pair("rpcport", ASSETCHAINS_RPCPORT));
|
||||
obj.push_back(Pair("magic", (int)ASSETCHAINS_MAGIC));
|
||||
if ( ASSETCHAINS_SUPPLY != 0 )
|
||||
obj.push_back(Pair("premine", ASSETCHAINS_SUPPLY));
|
||||
|
||||
@@ -168,42 +168,51 @@ UniValue getpeerinfo(const UniValue& params, bool fHelp)
|
||||
int32_t KOMODO_LONGESTCHAIN;
|
||||
int32_t komodo_longestchain()
|
||||
{
|
||||
static int32_t depth;
|
||||
int32_t ht,n=0,num=0,maxheight=0,height = 0;
|
||||
vector<CNodeStats> vstats;
|
||||
if ( depth < 0 )
|
||||
depth = 0;
|
||||
if ( depth == 0 )
|
||||
{
|
||||
LOCK(cs_main);
|
||||
CopyNodeStats(vstats);
|
||||
depth++;
|
||||
vector<CNodeStats> vstats;
|
||||
{
|
||||
//LOCK(cs_main);
|
||||
CopyNodeStats(vstats);
|
||||
}
|
||||
BOOST_FOREACH(const CNodeStats& stats, vstats)
|
||||
{
|
||||
//fprintf(stderr,"komodo_longestchain iter.%d\n",n);
|
||||
CNodeStateStats statestats;
|
||||
bool fStateStats = GetNodeStateStats(stats.nodeid,statestats);
|
||||
if ( statestats.nSyncHeight < 0 )
|
||||
continue;
|
||||
ht = 0;
|
||||
if ( stats.nStartingHeight > ht )
|
||||
ht = stats.nStartingHeight;
|
||||
if ( statestats.nSyncHeight > ht )
|
||||
ht = statestats.nSyncHeight;
|
||||
if ( statestats.nCommonHeight > ht )
|
||||
ht = statestats.nCommonHeight;
|
||||
if ( maxheight == 0 || ht > maxheight*1.01 )
|
||||
maxheight = ht, num = 1;
|
||||
else if ( ht > maxheight*0.99 )
|
||||
num++;
|
||||
if ( ht > height )
|
||||
height = ht;
|
||||
}
|
||||
depth--;
|
||||
if ( num > (n >> 1) )
|
||||
{
|
||||
extern char ASSETCHAINS_SYMBOL[];
|
||||
if ( 0 && height != KOMODO_LONGESTCHAIN )
|
||||
fprintf(stderr,"set %s KOMODO_LONGESTCHAIN <- %d\n",ASSETCHAINS_SYMBOL,height);
|
||||
KOMODO_LONGESTCHAIN = height;
|
||||
return(height);
|
||||
}
|
||||
KOMODO_LONGESTCHAIN = 0;
|
||||
}
|
||||
BOOST_FOREACH(const CNodeStats& stats, vstats)
|
||||
{
|
||||
//fprintf(stderr,"komodo_longestchain iter.%d\n",n);
|
||||
CNodeStateStats statestats;
|
||||
bool fStateStats = GetNodeStateStats(stats.nodeid,statestats);
|
||||
ht = 0;
|
||||
if ( stats.nStartingHeight > ht )
|
||||
ht = stats.nStartingHeight;
|
||||
if ( statestats.nSyncHeight > ht )
|
||||
ht = statestats.nSyncHeight;
|
||||
if ( statestats.nCommonHeight > ht )
|
||||
ht = statestats.nCommonHeight;
|
||||
if ( maxheight == 0 || ht > maxheight*1.01 )
|
||||
maxheight = ht, num = 1;
|
||||
else if ( ht > maxheight*0.99 )
|
||||
num++;
|
||||
n++;
|
||||
if ( ht > height )
|
||||
height = ht;
|
||||
}
|
||||
if ( num > (n >> 1) )
|
||||
{
|
||||
extern char ASSETCHAINS_SYMBOL[];
|
||||
if ( 0 && height != KOMODO_LONGESTCHAIN )
|
||||
fprintf(stderr,"set %s KOMODO_LONGESTCHAIN <- %d\n",ASSETCHAINS_SYMBOL,height);
|
||||
KOMODO_LONGESTCHAIN = height;
|
||||
return(height);
|
||||
}
|
||||
KOMODO_LONGESTCHAIN = 0;
|
||||
return(0);
|
||||
return(KOMODO_LONGESTCHAIN);
|
||||
}
|
||||
|
||||
UniValue addnode(const UniValue& params, bool fHelp)
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
using namespace std;
|
||||
|
||||
extern char ASSETCHAINS_SYMBOL[];
|
||||
int32_t komodo_dpowconfs(int32_t height,int32_t numconfs);
|
||||
|
||||
void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex)
|
||||
{
|
||||
@@ -230,7 +231,8 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue&
|
||||
|
||||
if (nConfirmations > 0) {
|
||||
entry.push_back(Pair("height", nHeight));
|
||||
entry.push_back(Pair("confirmations", nConfirmations));
|
||||
entry.push_back(Pair("confirmations", komodo_dpowconfs(nHeight,nConfirmations)));
|
||||
entry.push_back(Pair("rawconfirmations", nConfirmations));
|
||||
entry.push_back(Pair("time", nBlockTime));
|
||||
entry.push_back(Pair("blocktime", nBlockTime));
|
||||
} else {
|
||||
@@ -290,7 +292,8 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
|
||||
CBlockIndex* pindex = (*mi).second;
|
||||
if (chainActive.Contains(pindex)) {
|
||||
entry.push_back(Pair("height", pindex->nHeight));
|
||||
entry.push_back(Pair("confirmations", 1 + chainActive.Height() - pindex->nHeight));
|
||||
entry.push_back(Pair("rawconfirmations", 1 + chainActive.Height() - pindex->nHeight));
|
||||
entry.push_back(Pair("confirmations", komodo_dpowconfs(pindex->nHeight,1 + chainActive.Height() - pindex->nHeight)));
|
||||
entry.push_back(Pair("time", pindex->GetBlockTime()));
|
||||
entry.push_back(Pair("blocktime", pindex->GetBlockTime()));
|
||||
} else {
|
||||
@@ -477,7 +480,7 @@ int32_t gettxout_scriptPubKey(uint8_t *scriptPubKey,int32_t maxsize,uint256 txid
|
||||
uint256 hashBlock;
|
||||
if ( GetTransaction(txid,tx,hashBlock,false) == 0 )
|
||||
return(-1);
|
||||
else if ( n <= tx.vout.size() ) // vout.size() seems off by 1
|
||||
else if ( n < tx.vout.size() )
|
||||
{
|
||||
ptr = (uint8_t *)tx.vout[n].scriptPubKey.data();
|
||||
m = tx.vout[n].scriptPubKey.size();
|
||||
@@ -1055,35 +1058,65 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
|
||||
|
||||
// Use CTransaction for the constant parts of the
|
||||
// transaction to avoid rehashing.
|
||||
CMutableTransaction mergedTxsave = mergedTx;
|
||||
int32_t txpow,numiters = 0;
|
||||
const CTransaction txConst(mergedTx);
|
||||
// Sign what we can:
|
||||
for (unsigned int i = 0; i < mergedTx.vin.size(); i++) {
|
||||
CTxIn& txin = mergedTx.vin[i];
|
||||
const CCoins* coins = view.AccessCoins(txin.prevout.hash);
|
||||
if (coins == NULL || !coins->IsAvailable(txin.prevout.n)) {
|
||||
TxInErrorToJSON(txin, vErrors, "Input not found or already spent");
|
||||
continue;
|
||||
if ( (txpow= ASSETCHAINS_TXPOW) != 0 )
|
||||
{
|
||||
if ( txConst.IsCoinBase() != 0 )
|
||||
{
|
||||
if ( (txpow & 2) == 0 )
|
||||
txpow == 0;
|
||||
}
|
||||
const CScript& prevPubKey = coins->vout[txin.prevout.n].scriptPubKey;
|
||||
const CAmount& amount = coins->vout[txin.prevout.n].nValue;
|
||||
|
||||
SignatureData sigdata;
|
||||
// Only sign SIGHASH_SINGLE if there's a corresponding output:
|
||||
if (!fHashSingle || (i < mergedTx.vout.size()))
|
||||
ProduceSignature(MutableTransactionSignatureCreator(&keystore, &mergedTx, i, amount, nHashType), prevPubKey, sigdata, consensusBranchId);
|
||||
|
||||
// ... and merge in other signatures:
|
||||
BOOST_FOREACH(const CMutableTransaction& txv, txVariants) {
|
||||
sigdata = CombineSignatures(prevPubKey, TransactionSignatureChecker(&txConst, i, amount), sigdata, DataFromTransaction(txv, i), consensusBranchId);
|
||||
}
|
||||
|
||||
UpdateTransaction(mergedTx, i, sigdata);
|
||||
|
||||
ScriptError serror = SCRIPT_ERR_OK;
|
||||
if (!VerifyScript(txin.scriptSig, prevPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, TransactionSignatureChecker(&txConst, i, amount), consensusBranchId, &serror)) {
|
||||
TxInErrorToJSON(txin, vErrors, ScriptErrorString(serror));
|
||||
else
|
||||
{
|
||||
if ( (txpow & 1) == 0 )
|
||||
txpow == 0;
|
||||
}
|
||||
}
|
||||
while ( 1 )
|
||||
{
|
||||
if ( txpow != 0 )
|
||||
mergedTx = mergedTxsave;
|
||||
// Sign what we can:
|
||||
for (unsigned int i = 0; i < mergedTx.vin.size(); i++) {
|
||||
CTxIn& txin = mergedTx.vin[i];
|
||||
const CCoins* coins = view.AccessCoins(txin.prevout.hash);
|
||||
if (coins == NULL || !coins->IsAvailable(txin.prevout.n)) {
|
||||
TxInErrorToJSON(txin, vErrors, "Input not found or already spent");
|
||||
continue;
|
||||
}
|
||||
const CScript& prevPubKey = coins->vout[txin.prevout.n].scriptPubKey;
|
||||
const CAmount& amount = coins->vout[txin.prevout.n].nValue;
|
||||
|
||||
SignatureData sigdata;
|
||||
// Only sign SIGHASH_SINGLE if there's a corresponding output:
|
||||
if (!fHashSingle || (i < mergedTx.vout.size()))
|
||||
ProduceSignature(MutableTransactionSignatureCreator(&keystore, &mergedTx, i, amount, nHashType), prevPubKey, sigdata, consensusBranchId);
|
||||
|
||||
// ... and merge in other signatures:
|
||||
BOOST_FOREACH(const CMutableTransaction& txv, txVariants) {
|
||||
sigdata = CombineSignatures(prevPubKey, TransactionSignatureChecker(&txConst, i, amount), sigdata, DataFromTransaction(txv, i), consensusBranchId);
|
||||
}
|
||||
|
||||
UpdateTransaction(mergedTx, i, sigdata);
|
||||
|
||||
ScriptError serror = SCRIPT_ERR_OK;
|
||||
if (!VerifyScript(txin.scriptSig, prevPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, TransactionSignatureChecker(&txConst, i, amount), consensusBranchId, &serror)) {
|
||||
TxInErrorToJSON(txin, vErrors, ScriptErrorString(serror));
|
||||
}
|
||||
}
|
||||
if ( txpow != 0 )
|
||||
{
|
||||
uint256 txid = mergedTx.GetHash();
|
||||
if ( ((uint8_t *)&txid)[0] == 0 && ((uint8_t *)&txid)[31] == 0 )
|
||||
break;
|
||||
//fprintf(stderr,"%d: tmp txid.%s\n",numiters,txid.GetHex().c_str());
|
||||
} else break;
|
||||
numiters++;
|
||||
}
|
||||
if ( numiters > 0 )
|
||||
fprintf(stderr,"ASSETCHAINS_TXPOW.%d txpow.%d numiters.%d for signature\n",ASSETCHAINS_TXPOW,txpow,numiters);
|
||||
bool fComplete = vErrors.empty();
|
||||
|
||||
UniValue result(UniValue::VOBJ);
|
||||
|
||||
@@ -242,7 +242,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
||||
|
||||
UniValue stop(const UniValue& params, bool fHelp)
|
||||
{
|
||||
char buf[64];
|
||||
char buf[66+128];
|
||||
// Accept the deprecated and ignored 'detach' boolean argument
|
||||
if (fHelp || params.size() > 1)
|
||||
throw runtime_error(
|
||||
@@ -250,7 +250,7 @@ UniValue stop(const UniValue& params, bool fHelp)
|
||||
"\nStop Komodo server.");
|
||||
// Shutdown will take long enough that the response should get back
|
||||
StartShutdown();
|
||||
sprintf(buf,"%s Komodo server stopping",ASSETCHAINS_SYMBOL);
|
||||
sprintf(buf,"%s server stopping",ASSETCHAINS_SYMBOL[0] != 0 ? ASSETCHAINS_SYMBOL : "Komodo");
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -350,16 +350,16 @@ static const CRPCCommand vRPCCommands[] =
|
||||
#endif
|
||||
/* auction */
|
||||
{ "auction", "auctionaddress", &auctionaddress, true },
|
||||
|
||||
|
||||
/* lotto */
|
||||
{ "lotto", "lottoaddress", &lottoaddress, true },
|
||||
|
||||
|
||||
/* fsm */
|
||||
{ "FSM", "FSMaddress", &FSMaddress, true },
|
||||
{ "FSM", "FSMcreate", &FSMcreate, true },
|
||||
{ "FSM", "FSMlist", &FSMlist, true },
|
||||
{ "FSM", "FSMinfo", &FSMinfo, true },
|
||||
|
||||
|
||||
/* rewards */
|
||||
{ "rewards", "rewardslist", &rewardslist, true },
|
||||
{ "rewards", "rewardsinfo", &rewardsinfo, true },
|
||||
@@ -368,25 +368,24 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "rewards", "rewardslock", &rewardslock, true },
|
||||
{ "rewards", "rewardsunlock", &rewardsunlock, true },
|
||||
{ "rewards", "rewardsaddress", &rewardsaddress, true },
|
||||
|
||||
|
||||
/* faucet */
|
||||
{ "faucet", "faucetinfo", &faucetinfo, true },
|
||||
{ "faucet", "faucetfund", &faucetfund, true },
|
||||
{ "faucet", "faucetget", &faucetget, true },
|
||||
{ "faucet", "faucetaddress", &faucetaddress, true },
|
||||
|
||||
/* MofN */
|
||||
{ "MofN", "mofnaddress", &mofnaddress, true },
|
||||
|
||||
|
||||
/* Heir */
|
||||
{ "heir", "heiraddress", &heiraddress, true },
|
||||
|
||||
/* Channels */
|
||||
{ "channels", "channelsaddress", &channelsaddress, true },
|
||||
{ "channels", "channelsinfo", &channelsinfo, true },
|
||||
{ "channels", "channelsopen", &channelsopen, true },
|
||||
{ "channels", "channelspayment", &channelspayment, true },
|
||||
{ "channels", "channelscollect", &channelscollect, true },
|
||||
{ "channels", "channelsstop", &channelsstop, true },
|
||||
{ "channels", "channelsclose", &channelsclose, true },
|
||||
{ "channels", "channelsrefund", &channelsrefund, true },
|
||||
|
||||
|
||||
/* Oracles */
|
||||
{ "oracles", "oraclesaddress", &oraclesaddress, true },
|
||||
{ "oracles", "oracleslist", &oracleslist, true },
|
||||
@@ -396,7 +395,7 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "oracles", "oraclessubscribe", &oraclessubscribe, true },
|
||||
{ "oracles", "oraclesdata", &oraclesdata, true },
|
||||
{ "oracles", "oraclessamples", &oraclessamples, true },
|
||||
|
||||
|
||||
/* Prices */
|
||||
{ "prices", "pricesaddress", &pricesaddress, true },
|
||||
{ "prices", "priceslist", &priceslist, true },
|
||||
@@ -406,16 +405,16 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "prices", "pricesbet", &pricesbet, true },
|
||||
{ "prices", "pricesstatus", &pricesstatus, true },
|
||||
{ "prices", "pricesfinish", &pricesfinish, true },
|
||||
|
||||
|
||||
/* Pegs */
|
||||
{ "pegs", "pegsaddress", &pegsaddress, true },
|
||||
|
||||
|
||||
/* Triggers */
|
||||
{ "triggers", "triggersaddress", &triggersaddress, true },
|
||||
|
||||
|
||||
/* Payments */
|
||||
{ "payments", "paymentsaddress", &paymentsaddress, true },
|
||||
|
||||
|
||||
/* Gateways */
|
||||
{ "gateways", "gatewaysaddress", &gatewaysaddress, true },
|
||||
{ "gateways", "gatewayslist", &gatewayslist, true },
|
||||
@@ -427,6 +426,7 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "gateways", "gatewayspending", &gatewayspending, true },
|
||||
{ "gateways", "gatewaysmultisig", &gatewaysmultisig, true },
|
||||
{ "gateways", "gatewaysmarkdone", &gatewaysmarkdone, true },
|
||||
{ "gateways", "gatewayspartialsign", &gatewayspartialsign, true },
|
||||
|
||||
/* dice */
|
||||
{ "dice", "dicelist", &dicelist, true },
|
||||
@@ -522,6 +522,7 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "wallet", "sendmany", &sendmany, false },
|
||||
{ "wallet", "sendtoaddress", &sendtoaddress, false },
|
||||
{ "wallet", "setaccount", &setaccount, true },
|
||||
{ "wallet", "setpubkey", &setpubkey, true },
|
||||
{ "wallet", "settxfee", &settxfee, true },
|
||||
{ "wallet", "signmessage", &signmessage, true },
|
||||
{ "wallet", "walletlock", &walletlock, true },
|
||||
|
||||
@@ -222,7 +222,7 @@ extern UniValue tokenask(const UniValue& params, bool fHelp);
|
||||
extern UniValue tokencancelask(const UniValue& params, bool fHelp);
|
||||
extern UniValue tokenfillask(const UniValue& params, bool fHelp);
|
||||
extern UniValue tokenconvert(const UniValue& params, bool fHelp);
|
||||
extern UniValue mofnaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue heiraddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue channelsaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclesaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue oracleslist(const UniValue& params, bool fHelp);
|
||||
@@ -253,12 +253,11 @@ extern UniValue gatewayswithdraw(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewayspending(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewaysmarkdone(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewaysmultisig(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewayspartialsign(const UniValue& params, bool fHelp);
|
||||
extern UniValue channelsinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue channelsbind(const UniValue& params, bool fHelp);
|
||||
extern UniValue channelsopen(const UniValue& params, bool fHelp);
|
||||
extern UniValue channelspayment(const UniValue& params, bool fHelp);
|
||||
extern UniValue channelscollect(const UniValue& params, bool fHelp);
|
||||
extern UniValue channelsstop(const UniValue& params, bool fHelp);
|
||||
extern UniValue channelsclose(const UniValue& params, bool fHelp);
|
||||
extern UniValue channelsrefund(const UniValue& params, bool fHelp);
|
||||
|
||||
//extern UniValue tokenswapask(const UniValue& params, bool fHelp);
|
||||
@@ -324,6 +323,7 @@ extern UniValue walletlock(const UniValue& params, bool fHelp);
|
||||
extern UniValue encryptwallet(const UniValue& params, bool fHelp);
|
||||
extern UniValue validateaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue getinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue setpubkey(const UniValue& params, bool fHelp);
|
||||
extern UniValue getwalletinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue getblockchaininfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue getnetworkinfo(const UniValue& params, bool fHelp);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
using namespace std;
|
||||
|
||||
typedef vector<unsigned char> valtype;
|
||||
extern uint8_t ASSETCHAINS_TXPOW;
|
||||
|
||||
TransactionSignatureCreator::TransactionSignatureCreator(const CKeyStore* keystoreIn, const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : BaseSignatureCreator(keystoreIn), txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {}
|
||||
|
||||
@@ -32,8 +33,16 @@ bool TransactionSignatureCreator::CreateSig(std::vector<unsigned char>& vchSig,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!key.Sign(hash, vchSig))
|
||||
return false;
|
||||
if ( ASSETCHAINS_TXPOW == 0 )
|
||||
{
|
||||
if (!key.Sign(hash, vchSig))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!key.Sign(hash, vchSig, rand()))
|
||||
return false;
|
||||
}
|
||||
vchSig.push_back((unsigned char)nHashType);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
|
||||
CPubKey pubKey(vSolutions[0]);
|
||||
if (!pubKey.IsValid())
|
||||
{
|
||||
fprintf(stderr,"TX_PUBKEY invalid pubkey\n");
|
||||
//fprintf(stderr,"TX_PUBKEY invalid pubkey\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,8 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
||||
extern UniValue TxJoinSplitToJSON(const CTransaction& tx);
|
||||
extern uint8_t ASSETCHAINS_PRIVATE;
|
||||
uint32_t komodo_segid32(char *coinaddr);
|
||||
int32_t komodo_dpowconfs(int32_t height,int32_t numconfs);
|
||||
int32_t komodo_isnotaryvout(char *coinaddr); // from ac_private chains only
|
||||
|
||||
int64_t nWalletUnlockTime;
|
||||
static CCriticalSection cs_nWalletUnlockTime;
|
||||
@@ -89,16 +91,18 @@ void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry)
|
||||
{
|
||||
//int32_t i,n,txheight; uint32_t locktime; uint64_t interest = 0;
|
||||
int confirms = wtx.GetDepthInMainChain();
|
||||
entry.push_back(Pair("confirmations", confirms));
|
||||
entry.push_back(Pair("rawconfirmations", confirms));
|
||||
if (wtx.IsCoinBase())
|
||||
entry.push_back(Pair("generated", true));
|
||||
if (confirms > 0)
|
||||
{
|
||||
entry.push_back(Pair("confirmations", komodo_dpowconfs((int32_t)mapBlockIndex[wtx.hashBlock]->nHeight,confirms)));
|
||||
entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex()));
|
||||
entry.push_back(Pair("blockindex", wtx.nIndex));
|
||||
entry.push_back(Pair("blocktime", mapBlockIndex[wtx.hashBlock]->GetBlockTime()));
|
||||
entry.push_back(Pair("expiryheight", (int64_t)wtx.nExpiryHeight));
|
||||
}
|
||||
} else entry.push_back(Pair("confirmations", confirms));
|
||||
|
||||
uint256 hash = wtx.GetHash();
|
||||
entry.push_back(Pair("txid", hash.GetHex()));
|
||||
UniValue conflicts(UniValue::VARR);
|
||||
@@ -398,7 +402,7 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr
|
||||
|
||||
// Parse Zcash address
|
||||
CScript scriptPubKey = GetScriptForDestination(address);
|
||||
|
||||
|
||||
// Create and send the transaction
|
||||
CReserveKey reservekey(pwalletMain);
|
||||
CAmount nFeeRequired;
|
||||
@@ -2698,7 +2702,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
|
||||
|
||||
CAmount nValue = out.tx->vout[out.i].nValue;
|
||||
const CScript& pk = out.tx->vout[out.i].scriptPubKey;
|
||||
UniValue entry(UniValue::VOBJ);
|
||||
UniValue entry(UniValue::VOBJ); int32_t txheight = 0;
|
||||
entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
|
||||
entry.push_back(Pair("vout", out.i));
|
||||
entry.push_back(Pair("generated", out.tx->IsCoinBase()));
|
||||
@@ -2723,7 +2727,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
|
||||
{
|
||||
BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
|
||||
CBlockIndex *tipindex,*pindex = it->second;
|
||||
uint64_t interest; uint32_t locktime; int32_t txheight;
|
||||
uint64_t interest; uint32_t locktime;
|
||||
if ( pindex != 0 && (tipindex= chainActive.LastTip()) != 0 )
|
||||
{
|
||||
interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight);
|
||||
@@ -2732,7 +2736,10 @@ UniValue listunspent(const UniValue& params, bool fHelp)
|
||||
}
|
||||
//fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.LastTip(),locktime,txheight,pindex->nHeight);
|
||||
}
|
||||
entry.push_back(Pair("confirmations",out.nDepth));
|
||||
else if ( chainActive.LastTip() != 0 )
|
||||
txheight = (chainActive.LastTip()->nHeight - out.nDepth - 1);
|
||||
entry.push_back(Pair("rawconfirmations",out.nDepth));
|
||||
entry.push_back(Pair("confirmations",komodo_dpowconfs(txheight,out.nDepth)));
|
||||
entry.push_back(Pair("spendable", out.fSpendable));
|
||||
results.push_back(entry);
|
||||
}
|
||||
@@ -2743,7 +2750,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
|
||||
uint64_t komodo_interestsum()
|
||||
{
|
||||
#ifdef ENABLE_WALLET
|
||||
if ( GetBoolArg("-disablewallet", false) == 0 )
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && GetBoolArg("-disablewallet", false) == 0 )
|
||||
{
|
||||
uint64_t interest,sum = 0; int32_t txheight; uint32_t locktime;
|
||||
vector<COutput> vecOutputs;
|
||||
@@ -3415,6 +3422,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
|
||||
" \"txid\": xxxxx, (string) the transaction id\n"
|
||||
" \"amount\": xxxxx, (numeric) the amount of value in the note\n"
|
||||
" \"memo\": xxxxx, (string) hexademical string representation of memo field\n"
|
||||
" \"jsindex\": xxxxx, (numeric) the JoinSplit index\n"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("z_listreceivedbyaddress", "\"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\"")
|
||||
@@ -3456,6 +3464,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
|
||||
obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.plaintext.value))));
|
||||
std::string data(entry.plaintext.memo.begin(), entry.plaintext.memo.end());
|
||||
obj.push_back(Pair("memo", HexStr(data)));
|
||||
obj.push_back(Pair("jsindex", entry.jsop.js));
|
||||
result.push_back(obj);
|
||||
}
|
||||
return result;
|
||||
@@ -3793,7 +3802,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ")+address );
|
||||
}
|
||||
}
|
||||
else if ( ASSETCHAINS_PRIVATE != 0 )
|
||||
else if ( ASSETCHAINS_PRIVATE != 0 && komodo_isnotaryvout((char *)address.c_str()) == 0 )
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain");
|
||||
|
||||
if (setAddress.count(address))
|
||||
@@ -4525,13 +4534,16 @@ int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex);
|
||||
extern std::string NOTARY_PUBKEY;
|
||||
uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime,char *destaddr);
|
||||
int8_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout);
|
||||
int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n);
|
||||
void komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n);
|
||||
|
||||
int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33)
|
||||
{
|
||||
set<CBitcoinAddress> setAddress; uint8_t *script,utxosig[128]; uint256 utxotxid; uint64_t utxovalue; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector<COutput> vecOutputs; uint32_t utxovout,eligible,earliest = 0; CScript best_scriptPubKey; bool fNegative,fOverflow;
|
||||
bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr;
|
||||
auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus());
|
||||
if (!EnsureWalletIsAvailable(0))
|
||||
return 0;
|
||||
|
||||
const CKeyStore& keystore = *pwalletMain;
|
||||
assert(pwalletMain != NULL);
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
@@ -4692,6 +4704,9 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
|
||||
{
|
||||
static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime;
|
||||
set<CBitcoinAddress> setAddress; struct komodo_staking *kp; int32_t winners,segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector<COutput> vecOutputs; uint32_t block_from_future_rejecttime,besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock;
|
||||
if (!EnsureWalletIsAvailable(0))
|
||||
return 0;
|
||||
|
||||
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
|
||||
mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
||||
ratio = (mindiff / bnTarget);
|
||||
@@ -4901,6 +4916,70 @@ UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector<unsigned ch
|
||||
return(result);
|
||||
}
|
||||
|
||||
bool pubkey2addr(char *destaddr,uint8_t *pubkey33);
|
||||
|
||||
UniValue setpubkey(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ);
|
||||
if ( fHelp || params.size() != 1 )
|
||||
throw runtime_error(
|
||||
"setpubkey\n"
|
||||
"\nSets the -pubkey if the daemon was not started with it, if it was already set, it returns the pubkey.\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"pubkey\" (string) pubkey to set.\n"
|
||||
"\nResult:\n"
|
||||
" {\n"
|
||||
" \"pubkey\" : \"pubkey\", (string) The pubkey\n"
|
||||
" \"ismine\" : \"true/false\", (bool)\n"
|
||||
" \"R-address\" : \"R address\", (string) The pubkey\n"
|
||||
" }\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("setpubkey", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e")
|
||||
+ HelpExampleRpc("setpubkey", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e")
|
||||
);
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
LOCK2(cs_main, pwalletMain ? &pwalletMain->cs_wallet : NULL);
|
||||
#else
|
||||
LOCK(cs_main);
|
||||
#endif
|
||||
|
||||
char Raddress[18];
|
||||
uint8_t pubkey33[33];
|
||||
extern uint8_t NOTARY_PUBKEY33[];
|
||||
extern std::string NOTARY_PUBKEY;
|
||||
if ( NOTARY_PUBKEY33[0] == 0 ) {
|
||||
if (strlen(params[0].get_str().c_str()) == 66) {
|
||||
decode_hex(pubkey33,33,(char *)params[0].get_str().c_str());
|
||||
pubkey2addr((char *)Raddress,(uint8_t *)pubkey33);
|
||||
if (strcmp("RRmWExvapDM9YbLT9X9xAyzDgxomYf63ng",Raddress) == 0) {
|
||||
result.push_back(Pair("error", "pubkey entered is invalid."));
|
||||
} else {
|
||||
CBitcoinAddress address(Raddress);
|
||||
bool isValid = address.IsValid();
|
||||
if (isValid)
|
||||
{
|
||||
CTxDestination dest = address.Get();
|
||||
string currentAddress = address.ToString();
|
||||
result.push_back(Pair("address", currentAddress));
|
||||
#ifdef ENABLE_WALLET
|
||||
isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO;
|
||||
result.push_back(Pair("ismine", (mine & ISMINE_SPENDABLE) ? true : false));
|
||||
#endif
|
||||
}
|
||||
NOTARY_PUBKEY = params[0].get_str();
|
||||
decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str());
|
||||
}
|
||||
} else {
|
||||
result.push_back(Pair("error", "pubkey is wrong length, must be 66 char hex string."));
|
||||
}
|
||||
} else {
|
||||
result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon."));
|
||||
}
|
||||
result.push_back(Pair("pubkey", NOTARY_PUBKEY));
|
||||
return result;
|
||||
}
|
||||
|
||||
UniValue channelsaddress(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::vector<unsigned char> destpubkey; CPubKey pk,pk2; char destaddr[64];
|
||||
@@ -5016,17 +5095,17 @@ UniValue gatewaysaddress(const UniValue& params, bool fHelp)
|
||||
return(CCaddress(cp,(char *)"Gateways",pubkey));
|
||||
}
|
||||
|
||||
UniValue mofnaddress(const UniValue& params, bool fHelp)
|
||||
UniValue heiraddress(const UniValue& params, bool fHelp)
|
||||
{
|
||||
struct CCcontract_info *cp,C; std::vector<unsigned char> pubkey;
|
||||
cp = CCinit(&C,EVAL_MOFN);
|
||||
cp = CCinit(&C,EVAL_HEIR);
|
||||
if ( fHelp || params.size() > 1 )
|
||||
throw runtime_error("mofnaddress [pubkey]\n");
|
||||
throw runtime_error("heiraddress [pubkey]\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
if ( params.size() == 1 )
|
||||
pubkey = ParseHex(params[0].get_str().c_str());
|
||||
return(CCaddress(cp,(char *)"MofN",pubkey));
|
||||
return(CCaddress(cp,(char *)"Heir",pubkey));
|
||||
}
|
||||
|
||||
UniValue lottoaddress(const UniValue& params, bool fHelp)
|
||||
@@ -5124,11 +5203,15 @@ UniValue tokenaddress(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue channelsinfo(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if ( fHelp || params.size() != 0 )
|
||||
throw runtime_error("channelsinfo\n");
|
||||
uint256 opentxid;
|
||||
if ( fHelp || params.size() > 1 )
|
||||
throw runtime_error("channelsinfo [opentxid]\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
return(ChannelsInfo());
|
||||
opentxid=zeroid;
|
||||
if (params.size() > 0 && !params[0].isNull() && !params[0].get_str().empty())
|
||||
opentxid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
return(ChannelsInfo(opentxid));
|
||||
}
|
||||
|
||||
UniValue channelsopen(const UniValue& params, bool fHelp)
|
||||
@@ -5142,8 +5225,23 @@ UniValue channelsopen(const UniValue& params, bool fHelp)
|
||||
const CKeyStore& keystore = *pwalletMain;
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
destpub = ParseHex(params[0].get_str().c_str());
|
||||
if (destpub.size()!= 33)
|
||||
{
|
||||
ERR_RESULT("invalid destination pubkey");
|
||||
return result;
|
||||
}
|
||||
numpayments = atoi(params[1].get_str().c_str());
|
||||
if (numpayments <1)
|
||||
{
|
||||
ERR_RESULT("invalid number of payments, must be greater than 0");
|
||||
return result;
|
||||
}
|
||||
payment = atol(params[2].get_str().c_str());
|
||||
if (payment <1)
|
||||
{
|
||||
ERR_RESULT("invalid payment amount, must be greater than 0");
|
||||
return result;
|
||||
}
|
||||
hex = ChannelOpen(0,pubkey2pk(destpub),numpayments,payment);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
@@ -5153,42 +5251,28 @@ UniValue channelsopen(const UniValue& params, bool fHelp)
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue channelsstop(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); std::vector<unsigned char> destpub; struct CCcontract_info *cp,C; std::string hex; uint256 origtxid;
|
||||
cp = CCinit(&C,EVAL_CHANNELS);
|
||||
if ( fHelp || params.size() != 2 )
|
||||
throw runtime_error("channelsstop destpubkey origtxid\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
const CKeyStore& keystore = *pwalletMain;
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
destpub = ParseHex(params[0].get_str().c_str());
|
||||
origtxid = Parseuint256((char *)params[1].get_str().c_str());
|
||||
hex = ChannelStop(0,pubkey2pk(destpub),origtxid);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else ERR_RESULT("couldnt create channelsstop transaction");
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue channelspayment(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 origtxid,prevtxid; int32_t n; int64_t amount;
|
||||
UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,secret=zeroid; int32_t n; int64_t amount;
|
||||
cp = CCinit(&C,EVAL_CHANNELS);
|
||||
if ( fHelp || params.size() != 4 )
|
||||
throw runtime_error("channelspayment prevtxid origtxid n amount\n");
|
||||
if ( fHelp || params.size() != 2 )
|
||||
throw runtime_error("channelspayment opentxid amount [secret]\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
const CKeyStore& keystore = *pwalletMain;
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
prevtxid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
origtxid = Parseuint256((char *)params[1].get_str().c_str());
|
||||
n = atoi((char *)params[2].get_str().c_str());
|
||||
amount = atoi((char *)params[3].get_str().c_str());
|
||||
hex = ChannelPayment(0,prevtxid,origtxid,n,amount);
|
||||
opentxid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
amount = atoi((char *)params[1].get_str().c_str());
|
||||
if (amount <1)
|
||||
{
|
||||
ERR_RESULT("invalid payment amount, must be greater than 0");
|
||||
return result;
|
||||
}
|
||||
if (params.size() > 2 && !params[2].isNull() && !params[2].get_str().empty())
|
||||
{
|
||||
secret = Parseuint256((char *)params[2].get_str().c_str());
|
||||
}
|
||||
hex = ChannelPayment(0,opentxid,amount,secret);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
@@ -5197,42 +5281,39 @@ UniValue channelspayment(const UniValue& params, bool fHelp)
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue channelscollect(const UniValue& params, bool fHelp)
|
||||
UniValue channelsclose(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 origtxid,paytxid; int32_t n; int64_t amount;
|
||||
UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid;
|
||||
cp = CCinit(&C,EVAL_CHANNELS);
|
||||
if ( fHelp || params.size() != 4 )
|
||||
throw runtime_error("channelscollect paytxid origtxid n amount\n");
|
||||
if ( fHelp || params.size() != 1 )
|
||||
throw runtime_error("channelsclose opentxid\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
const CKeyStore& keystore = *pwalletMain;
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
paytxid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
origtxid = Parseuint256((char *)params[1].get_str().c_str());
|
||||
n = atoi((char *)params[2].get_str().c_str());
|
||||
amount = atoi((char *)params[3].get_str().c_str());
|
||||
hex = ChannelCollect(0,paytxid,origtxid,n,amount);
|
||||
opentxid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
hex = ChannelClose(0,opentxid);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else ERR_RESULT("couldnt create channelscollect transaction");
|
||||
} else ERR_RESULT("couldnt create channelsclose transaction");
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue channelsrefund(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 origtxid,stoptxid;
|
||||
UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,closetxid;
|
||||
cp = CCinit(&C,EVAL_CHANNELS);
|
||||
if ( fHelp || params.size() != 2 )
|
||||
throw runtime_error("channelsrefund stoptxid origtxid\n");
|
||||
throw runtime_error("channelsrefund opentxid closetxid\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
const CKeyStore& keystore = *pwalletMain;
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
stoptxid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
origtxid = Parseuint256((char *)params[1].get_str().c_str());
|
||||
hex = ChannelRefund(0,stoptxid,origtxid);
|
||||
opentxid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
closetxid = Parseuint256((char *)params[1].get_str().c_str());
|
||||
hex = ChannelRefund(0,opentxid,closetxid);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
@@ -5539,10 +5620,10 @@ UniValue gatewayswithdraw(const UniValue& params, bool fHelp)
|
||||
const CKeyStore& keystore = *pwalletMain;
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
bindtxid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
coin = params[1].get_str();
|
||||
coin = params[1].get_str();
|
||||
withdrawpub = ParseHex(params[2].get_str());
|
||||
amount = atof((char *)params[3].get_str().c_str()) * COIN;
|
||||
hex = GatewaysWithdraw(0,bindtxid,coin,withdrawpub,amount);
|
||||
hex = GatewaysWithdraw(0,bindtxid,coin,pubkey2pk(withdrawpub),amount);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
@@ -5554,7 +5635,7 @@ UniValue gatewayswithdraw(const UniValue& params, bool fHelp)
|
||||
UniValue gatewaysmarkdone(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); uint256 withdrawtxid,cointxid; std::string hex,coin;
|
||||
if ( fHelp || params.size() != 1 )
|
||||
if ( fHelp || params.size() != 3 )
|
||||
throw runtime_error("gatewaysmarkdone withdrawtxid coin cointxid\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
@@ -5586,18 +5667,30 @@ UniValue gatewayspending(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue gatewaysmultisig(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); uint256 bindtxid,withtxid; std::string coin,hex; char *txidaddr;
|
||||
if ( fHelp || params.size() != 2 )
|
||||
throw runtime_error("gatewaysmultisig bindtxid coin withtxid txidaddr\n");
|
||||
UniValue result(UniValue::VOBJ); std::string hex; char *txidaddr;
|
||||
if ( fHelp || params.size() != 1 )
|
||||
throw runtime_error("gatewaysmultisig txidaddr\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
const CKeyStore& keystore = *pwalletMain;
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
bindtxid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
txidaddr = (char *)params[0].get_str().c_str();
|
||||
return(GatewaysMultisig(txidaddr));
|
||||
}
|
||||
|
||||
UniValue gatewayspartialsign(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); std::string coin,parthex,hex; uint256 txid;
|
||||
if ( fHelp || params.size() != 3 )
|
||||
throw runtime_error("gatewayspartialsign txidaddr refcoin hex\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
const CKeyStore& keystore = *pwalletMain;
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
txid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
coin = params[1].get_str();
|
||||
withtxid = Parseuint256((char *)params[2].get_str().c_str());
|
||||
txidaddr = (char *)params[3].get_str().c_str();
|
||||
hex = GatewaysMultisig(0,coin,bindtxid,withtxid,txidaddr);
|
||||
parthex = params[2].get_str();
|
||||
hex = GatewaysPartialSign(0,txid,coin,parthex);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
@@ -5636,7 +5729,8 @@ UniValue oraclesregister(const UniValue& params, bool fHelp)
|
||||
const CKeyStore& keystore = *pwalletMain;
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
txid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
datafee = atol((char *)params[1].get_str().c_str());
|
||||
if ( (datafee= atol((char *)params[1].get_str().c_str())) == 0 )
|
||||
datafee = atof((char *)params[1].get_str().c_str()) * COIN;
|
||||
hex = OracleRegister(0,txid,datafee);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
@@ -5669,7 +5763,7 @@ UniValue oraclessubscribe(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue oraclessamples(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); uint256 txid,batontxid; int32_t num;
|
||||
UniValue result(UniValue::VOBJ); uint256 txid,batontxid; int32_t num;
|
||||
if ( fHelp || params.size() != 3 )
|
||||
throw runtime_error("oraclessamples oracletxid batonutxo num\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
@@ -5727,6 +5821,24 @@ UniValue oraclescreate(const UniValue& params, bool fHelp)
|
||||
ERR_RESULT("oracles format must be <= 4096 characters");
|
||||
return(result);
|
||||
}
|
||||
// list of oracle valid formats from oracles.cpp -> oracle_format
|
||||
const UniValue valid_formats[13] = {"s","S","d","D","c","C","t","T","i","I","l","L","h"};
|
||||
const UniValue header_type = "Ihh";
|
||||
// checking if oracle data type is valid
|
||||
bool is_valid_format = false;
|
||||
for ( int i = 0; i < 13; ++i ) {
|
||||
if ( valid_formats[i].get_str() == format ) {
|
||||
is_valid_format = true;
|
||||
}
|
||||
}
|
||||
// additional check for special Ihh data type
|
||||
if ( format == header_type.get_str() ) {
|
||||
is_valid_format = true;
|
||||
}
|
||||
if ( !is_valid_format ) {
|
||||
ERR_RESULT("oracles format not valid");
|
||||
return(result);
|
||||
}
|
||||
hex = OracleCreate(0,name,description,format);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
@@ -6038,7 +6150,7 @@ UniValue diceaddfunds(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue dicebet(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); std::string hex; uint256 fundingtxid; int64_t amount,odds; char *name;
|
||||
UniValue result(UniValue::VOBJ); std::string hex,error; uint256 fundingtxid; int64_t amount,odds; char *name;
|
||||
if ( fHelp || params.size() != 4 )
|
||||
throw runtime_error("dicebet name fundingtxid amount odds\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
@@ -6056,14 +6168,12 @@ UniValue dicebet(const UniValue& params, bool fHelp)
|
||||
}
|
||||
if (amount > 0 && odds > 0) {
|
||||
hex = DiceBet(0,name,fundingtxid,amount,odds);
|
||||
if ( CCerror != "" )
|
||||
{
|
||||
ERR_RESULT(CCerror);
|
||||
} else if ( hex.size() > 0 )
|
||||
RETURN_IF_ERROR(CCerror);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else ERR_RESULT("couldnt create dice bet transaction. make sure your address has funds");
|
||||
}
|
||||
} else {
|
||||
ERR_RESULT("amount and odds must be positive");
|
||||
}
|
||||
@@ -6072,7 +6182,7 @@ UniValue dicebet(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue dicefinish(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; std::string hex; int32_t r;
|
||||
UniValue result(UniValue::VOBJ); uint8_t funcid; char *name; uint256 entropyused,fundingtxid,bettxid; std::string hex; int32_t r,entropyvout;
|
||||
if ( fHelp || params.size() != 3 )
|
||||
throw runtime_error("dicefinish name fundingtxid bettxid\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
@@ -6086,7 +6196,7 @@ UniValue dicefinish(const UniValue& params, bool fHelp)
|
||||
}
|
||||
fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
|
||||
bettxid = Parseuint256((char *)params[2].get_str().c_str());
|
||||
hex = DiceBetFinish(&r,0,name,fundingtxid,bettxid,1);
|
||||
hex = DiceBetFinish(funcid,entropyused,entropyvout,&r,0,name,fundingtxid,bettxid,1,zeroid,-1);
|
||||
if ( CCerror != "" )
|
||||
{
|
||||
ERR_RESULT(CCerror);
|
||||
@@ -6094,13 +6204,20 @@ UniValue dicefinish(const UniValue& params, bool fHelp)
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
if ( funcid != 0 )
|
||||
{
|
||||
char funcidstr[2];
|
||||
funcidstr[0] = funcid;
|
||||
funcidstr[1] = 0;
|
||||
result.push_back(Pair("funcid", funcidstr));
|
||||
}
|
||||
} else ERR_RESULT( "couldnt create dicefinish transaction");
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue dicestatus(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; std::string status; double winnings;
|
||||
UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; std::string status,error; double winnings;
|
||||
if ( fHelp || (params.size() != 2 && params.size() != 3) )
|
||||
throw runtime_error("dicestatus name fundingtxid bettxid\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
@@ -6117,10 +6234,8 @@ UniValue dicestatus(const UniValue& params, bool fHelp)
|
||||
if ( params.size() == 3 )
|
||||
bettxid = Parseuint256((char *)params[2].get_str().c_str());
|
||||
winnings = DiceStatus(0,name,fundingtxid,bettxid);
|
||||
if (CCerror != "") {
|
||||
ERR_RESULT(CCerror);
|
||||
return result;
|
||||
}
|
||||
RETURN_IF_ERROR(CCerror);
|
||||
|
||||
result.push_back(Pair("result", "success"));
|
||||
if ( winnings >= 0. )
|
||||
{
|
||||
@@ -6582,6 +6697,9 @@ UniValue getbalance64(const UniValue& params, bool fHelp)
|
||||
{
|
||||
set<CBitcoinAddress> setAddress; vector<COutput> vecOutputs;
|
||||
UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR),b(UniValue::VARR); CTxDestination address;
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return NullUniValue;
|
||||
|
||||
const CKeyStore& keystore = *pwalletMain;
|
||||
CAmount nValues[64],nValues2[64],nValue,total,total2; int32_t i,segid;
|
||||
assert(pwalletMain != NULL);
|
||||
|
||||
@@ -1208,4 +1208,6 @@ public:
|
||||
/** Error status printout */
|
||||
#define ERR_RESULT(x) result.push_back(Pair("result", "error")) , result.push_back(Pair("error", x));
|
||||
|
||||
#define RETURN_IF_ERROR(CCerror) if ( CCerror != "" ) { ERR_RESULT(CCerror); return(result); }
|
||||
|
||||
#endif // BITCOIN_WALLET_WALLET_H
|
||||
|
||||
Reference in New Issue
Block a user