Merge branch 'FSM' into jl777
This commit is contained in:
@@ -26,6 +26,14 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework):
|
||||
rpc = self.nodes[0]
|
||||
rpc1 = self.nodes[1]
|
||||
|
||||
# checking channelsaddress call
|
||||
|
||||
result = rpc.channelsaddress(self.pubkey)
|
||||
assert_success(result)
|
||||
# test that additional CCaddress key is returned
|
||||
for x in ['myCCaddress', 'ChannelsCCaddress', 'Channelsmarker', 'myaddress', 'CCaddress']:
|
||||
assert_equal(result[x][0], 'R')
|
||||
|
||||
# getting empty channels list
|
||||
result = rpc.channelslist()
|
||||
assert_equal(len(result), 2)
|
||||
@@ -143,7 +151,7 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework):
|
||||
refund_txid = self.send_and_mine(result["hex"], rpc)
|
||||
assert refund_txid, "got txid"
|
||||
|
||||
# TODO: check if it refunded to opener address
|
||||
# checking if it refunded to opener address
|
||||
raw_transaction = rpc.getrawtransaction(refund_txid, 1)
|
||||
|
||||
result = raw_transaction["vout"][2]["valueSat"]
|
||||
|
||||
@@ -34,21 +34,18 @@ class CryptoconditionsHeirTest(CryptoconditionsTestFramework):
|
||||
|
||||
# getting empty heir list
|
||||
result = rpc.heirlist()
|
||||
assert_equal(len(result), 1)
|
||||
assert_success(result)
|
||||
assert_equal(result, [])
|
||||
|
||||
# valid heirfund case with coins
|
||||
result = rpc.heirfund("0", "1000", "UNITHEIR", self.pubkey1, "10")
|
||||
result = rpc.heirfund("0", "1000", "UNITHEIR", self.pubkey1, "10", "TESTMEMO")
|
||||
assert_success(result)
|
||||
|
||||
heir_fund_txid = self.send_and_mine(result["hextx"], rpc)
|
||||
heir_fund_txid = self.send_and_mine(result["hex"], rpc)
|
||||
assert heir_fund_txid, "got heir funding txid"
|
||||
|
||||
# heir fund txid should be in heirlist now
|
||||
result = rpc.heirlist()
|
||||
assert_equal(len(result), 2)
|
||||
assert_success(result)
|
||||
assert_equal(result["fundingtxid"], heir_fund_txid)
|
||||
assert_equal(result, [heir_fund_txid])
|
||||
|
||||
# checking heirinfo
|
||||
result = rpc.heirinfo(heir_fund_txid)
|
||||
@@ -57,20 +54,20 @@ class CryptoconditionsHeirTest(CryptoconditionsTestFramework):
|
||||
assert_equal(result["name"], "UNITHEIR")
|
||||
assert_equal(result["owner"], self.pubkey)
|
||||
assert_equal(result["heir"], self.pubkey1)
|
||||
assert_equal(result["funding total in coins"], "1000.00000000")
|
||||
assert_equal(result["funding available in coins"], "1000.00000000")
|
||||
assert_equal(result["inactivity time setting, sec"], "10")
|
||||
assert_equal(result["spending allowed for the heir"], "false")
|
||||
|
||||
# TODO: heirlist keys are duplicating now
|
||||
assert_equal(result["memo"], "TESTMEMO")
|
||||
assert_equal(result["lifetime"], "1000.00000000")
|
||||
assert_equal(result["type"], "coins")
|
||||
assert_equal(result["InactivityTimeSetting"], "10")
|
||||
assert_equal(result["InactivityTime"], "0")
|
||||
assert_equal(result["IsHeirSpendingAllowed"], "false")
|
||||
|
||||
# waiting for 11 seconds to be sure that needed time passed for heir claiming
|
||||
time.sleep(11)
|
||||
rpc.generate(1)
|
||||
self.sync_all()
|
||||
result = rpc.heirinfo(heir_fund_txid)
|
||||
assert_equal(result["funding available in coins"], "1000.00000000")
|
||||
assert_equal(result["spending allowed for the heir"], "true")
|
||||
assert_equal(result["lifetime"], "1000.00000000")
|
||||
assert_equal(result["IsHeirSpendingAllowed"], "true")
|
||||
|
||||
# have to check that second node have coins to cover txfee at least
|
||||
rpc.sendtoaddress(rpc1.getnewaddress(), 1)
|
||||
@@ -84,7 +81,7 @@ class CryptoconditionsHeirTest(CryptoconditionsTestFramework):
|
||||
result = rpc1.heirclaim("0", "1000", heir_fund_txid)
|
||||
assert_success(result)
|
||||
|
||||
heir_claim_txid = self.send_and_mine(result["hextx"], rpc1)
|
||||
heir_claim_txid = self.send_and_mine(result["hex"], rpc1)
|
||||
assert heir_claim_txid, "got claim txid"
|
||||
|
||||
# balance of second node after heirclaim should increase for 1000 coins - txfees
|
||||
@@ -96,9 +93,63 @@ class CryptoconditionsHeirTest(CryptoconditionsTestFramework):
|
||||
|
||||
# no more funds should be available for claiming
|
||||
result = rpc.heirinfo(heir_fund_txid)
|
||||
assert_equal(result["funding available in coins"], "0.00000000")
|
||||
assert_equal(result["lifetime"], "1000.00000000")
|
||||
assert_equal(result["available"], "0.00000000")
|
||||
|
||||
# TODO: valid heirfund case with tokens
|
||||
# creating tokens which we put to heir contract
|
||||
token_hex = rpc.tokencreate("TEST", "1", "TESTING")
|
||||
token_txid = self.send_and_mine(token_hex["hex"], rpc)
|
||||
assert token_txid, "got token txid"
|
||||
|
||||
# checking possesion over the tokens and balance
|
||||
result = rpc.tokenbalance(token_txid, self.pubkey)["balance"]
|
||||
assert_equal(result, 100000000)
|
||||
|
||||
# valid heir case with tokens
|
||||
token_heir_hex = rpc.heirfund("0", "100000000", "UNITHEIR", self.pubkey1, "10", "TESTMEMO", token_txid)
|
||||
token_heir_txid = self.send_and_mine(token_heir_hex["hex"], rpc)
|
||||
assert token_heir_txid, "got txid of heirfund with tokens"
|
||||
|
||||
self.sync_all()
|
||||
|
||||
# checking heirinfo
|
||||
result = rpc.heirinfo(token_heir_txid)
|
||||
assert_success(result)
|
||||
assert_equal(result["fundingtxid"], token_heir_txid)
|
||||
assert_equal(result["name"], "UNITHEIR")
|
||||
assert_equal(result["owner"], self.pubkey)
|
||||
assert_equal(result["heir"], self.pubkey1)
|
||||
assert_equal(result["lifetime"], "100000000")
|
||||
assert_equal(result["type"], "tokens")
|
||||
assert_equal(result["InactivityTimeSetting"], "10")
|
||||
assert_equal(result["InactivityTime"], "0")
|
||||
assert_equal(result["IsHeirSpendingAllowed"], "false")
|
||||
|
||||
# waiting for 11 seconds to be sure that needed time passed for heir claiming
|
||||
time.sleep(11)
|
||||
rpc.generate(1)
|
||||
self.sync_all()
|
||||
result = rpc.heirinfo(token_heir_txid)
|
||||
assert_equal(result["lifetime"], "100000000")
|
||||
assert_equal(result["IsHeirSpendingAllowed"], "true")
|
||||
|
||||
# let's claim whole heir sum from second node
|
||||
result = rpc1.heirclaim("0", "100000000", token_heir_txid)
|
||||
assert_success(result)
|
||||
|
||||
heir_tokens_claim_txid = self.send_and_mine(result["hex"], rpc1)
|
||||
assert heir_tokens_claim_txid, "got claim txid"
|
||||
|
||||
# claiming node should have correct token balance now
|
||||
result = rpc1.tokenbalance(token_txid, self.pubkey1)["balance"]
|
||||
assert_equal(result, 100000000)
|
||||
|
||||
self.sync_all()
|
||||
|
||||
# no more funds should be available for claiming
|
||||
result = rpc.heirinfo(token_heir_txid)
|
||||
assert_equal(result["lifetime"], "100000000")
|
||||
assert_equal(result["available"], "0")
|
||||
|
||||
def run_test(self):
|
||||
print("Mining blocks...")
|
||||
|
||||
@@ -28,10 +28,9 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin
|
||||
std::string GatewaysPartialSign(uint64_t txfee,uint256 txidaddr,std::string refcoin,std::string hex);
|
||||
std::string GatewaysCompleteSigning(uint64_t txfee,uint256 txidaddr,std::string refcoin,std::string hex);
|
||||
std::string GatewaysMarkDone(uint64_t txfee,uint256 withdrawtxid,std::string refcoin);
|
||||
UniValue GatewaysPendingDeposits(uint256 bindtxid,std::string refcoin);
|
||||
UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin);
|
||||
UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin);
|
||||
UniValue GatewaysMultisig(char *txidaddr);
|
||||
|
||||
|
||||
// CCcustom
|
||||
UniValue GatewaysInfo(uint256 bindtxid);
|
||||
|
||||
@@ -27,15 +27,11 @@ bool HeirValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,
|
||||
class CoinHelper;
|
||||
class TokenHelper;
|
||||
|
||||
UniValue HeirFundCoinCaller(int64_t txfee, int64_t satoshis, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid);
|
||||
UniValue HeirFundTokenCaller(int64_t txfee, int64_t satoshis, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid);
|
||||
UniValue HeirFundCoinCaller(int64_t txfee, int64_t coins, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string memo);
|
||||
UniValue HeirFundTokenCaller(int64_t txfee, int64_t satoshis, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string memo, uint256 tokenid);
|
||||
UniValue HeirClaimCaller(uint256 fundingtxid, int64_t txfee, std::string amount);
|
||||
UniValue HeirAddCaller(uint256 fundingtxid, int64_t txfee, std::string amount);
|
||||
|
||||
UniValue HeirInfo(uint256 fundingtxid);
|
||||
UniValue HeirList();
|
||||
//std::string Heir_MakeBadTx(uint256 fundingtxid, uint8_t funcId, int64_t amount, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTime, uint32_t errMask);
|
||||
|
||||
//bool HeirExactTokenAmounts(bool compareTotals, struct CCcontract_info *cpHeir, Eval* eval, uint256 assetid, const CTransaction &tx);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -242,7 +242,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran
|
||||
if ( flag == 0 )
|
||||
{
|
||||
fprintf(stderr,"CC signing error: vini.%d has unknown CC address.(%s)\n",i,destaddr);
|
||||
continue;
|
||||
return("");
|
||||
}
|
||||
}
|
||||
uint256 sighash = SignatureHash(CCPubKey(cond), mtx, i, SIGHASH_ALL, utxovalues[i],consensusBranchId, &txdata);
|
||||
@@ -390,9 +390,9 @@ int64_t CCfullsupply(uint256 tokenid)
|
||||
return(0);
|
||||
}
|
||||
|
||||
int64_t CCtoken_balance(char *coinaddr,uint256 tokenid)
|
||||
int64_t CCtoken_balance(char *coinaddr,uint256 reftokenid)
|
||||
{
|
||||
int64_t price,sum = 0; int32_t numvouts; CTransaction tx; uint256 assetid,assetid2,txid,hashBlock;
|
||||
int64_t price,sum = 0; int32_t numvouts; CTransaction tx; uint256 tokenid,txid,hashBlock;
|
||||
std::vector<uint8_t> vopretExtra;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
uint8_t evalCode;
|
||||
@@ -401,11 +401,11 @@ int64_t CCtoken_balance(char *coinaddr,uint256 tokenid)
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 )
|
||||
if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0 )
|
||||
{
|
||||
char str[65]; fprintf(stderr,"check %s %.8f\n",uint256_str(str,txid),(double)it->second.satoshis/COIN);
|
||||
char str[65];
|
||||
std::vector<CPubKey> voutTokenPubkeys;
|
||||
if ( DecodeTokenOpRet(tx.vout[numvouts-1].scriptPubKey, evalCode, assetid, voutTokenPubkeys, vopretExtra) != 0 && assetid == tokenid )
|
||||
if ( reftokenid==txid || (DecodeTokenOpRet(tx.vout[numvouts-1].scriptPubKey, evalCode, tokenid, voutTokenPubkeys, vopretExtra) != 0 && reftokenid == tokenid))
|
||||
{
|
||||
sum += it->second.satoshis;
|
||||
}
|
||||
|
||||
@@ -475,7 +475,7 @@ int32_t get_coinheader(char *refcoin,char *acname,bits256 *blockhashp,bits256 *m
|
||||
cJSON *get_gatewayspending(char *refcoin,char *acname,char *bindtxidstr)
|
||||
{
|
||||
cJSON *retjson; char *retstr;
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspending",bindtxidstr,refcoin,"","")) != 0 )
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspendingwithdraws",bindtxidstr,refcoin,"","")) != 0 )
|
||||
{
|
||||
//printf("pending.(%s)\n",jprint(retjson,0));
|
||||
return(retjson);
|
||||
@@ -588,13 +588,12 @@ void importaddress(char *refcoin,char *acname,char *depositaddr, char *label,int
|
||||
}
|
||||
}
|
||||
|
||||
void addmultisigaddress(char *refcoin,char *acname,int32_t M, char *pubkeys,char *bindtxidstr)
|
||||
void addmultisigaddress(char *refcoin,char *acname,int32_t M, char *pubkeys)
|
||||
{
|
||||
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 )
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"addmultisigaddress",Mstr,pubkeys,"","")) != 0 )
|
||||
{
|
||||
fprintf(stderr,"unexpected addmultisigaddress json.(%s)\n",jprint(retjson,0));
|
||||
free(retstr);
|
||||
@@ -644,7 +643,6 @@ char *createrawtx(char *refcoin,char *acname,char *depositaddr,char *withdrawadd
|
||||
printf("createrawtx satoshis %.8f < txfee %.8f\n",(double)satoshis/SATOSHIDEN,(double)txfee/SATOSHIDEN);
|
||||
return(0);
|
||||
}
|
||||
satoshis -= txfee;
|
||||
sprintf(array,"\'[\"%s\"]\'",depositaddr);
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"listunspent","1","99999999",array,"")) != 0 )
|
||||
{
|
||||
@@ -699,7 +697,7 @@ cJSON *addsignature(char *refcoin,char *acname,char *rawtx)
|
||||
{
|
||||
if ( is_cJSON_True(jobj(retjson,"complete")) != 0 )
|
||||
return(retjson);
|
||||
else if ( (hexstr= jstr(retjson,"hex")) != 0 && strlen(hexstr) > strlen(rawtx) )
|
||||
else if ( (hexstr= jstr(retjson,"hex")) != 0 && strlen(hexstr) > strlen(rawtx) + 2 )
|
||||
{
|
||||
jaddnum(retjson,"partialtx",1);
|
||||
return(retjson);
|
||||
@@ -714,32 +712,14 @@ cJSON *addsignature(char *refcoin,char *acname,char *rawtx)
|
||||
return(0);
|
||||
}
|
||||
|
||||
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",txidaddr,"","","")) != 0 )
|
||||
{
|
||||
if ((hexstr=jstr(retjson,"hex")) != 0 )
|
||||
{
|
||||
if (strlen(hexstr)>0) hex = clonestr(hexstr);
|
||||
}
|
||||
*K=jint(retjson,"number_of_signs");
|
||||
free_json(retjson);
|
||||
}
|
||||
else if ( retstr != 0 )
|
||||
{
|
||||
printf("error parsing gatewaysmultisig.(%s)\n",retstr);
|
||||
free(retstr);
|
||||
}
|
||||
return(hex);
|
||||
}
|
||||
|
||||
bits256 gatewayspartialsign(char *refcoin,char *acname,bits256 txid,char *hex)
|
||||
bits256 gatewayspartialsign(char *refcoin,char *acname,bits256 txid,char *coin,char *hex)
|
||||
{
|
||||
char str[65],*retstr; cJSON *retjson;
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspartialsign",bits256_str(str,txid),refcoin,hex,"")) != 0 )
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspartialsign",bits256_str(str,txid),coin,hex,"")) != 0 )
|
||||
{
|
||||
return(komodobroadcast(refcoin,acname,retjson));
|
||||
txid=komodobroadcast(refcoin,acname,retjson);
|
||||
free(retjson);
|
||||
return (txid);
|
||||
}
|
||||
else if ( retstr != 0 )
|
||||
{
|
||||
@@ -749,36 +729,38 @@ bits256 gatewayspartialsign(char *refcoin,char *acname,bits256 txid,char *hex)
|
||||
return (zeroid);
|
||||
}
|
||||
|
||||
void gatewayscompletesigning(char *refcoin,char *acname,bits256 withtxid,char *coin,char *hex)
|
||||
bits256 gatewayscompletesigning(char *refcoin,char *acname,bits256 withtxid,char *coin,char *hex)
|
||||
{
|
||||
char str[65],str2[65],*retstr; cJSON *retjson;
|
||||
printf("spend %s %s/v2 as marker\n",acname,bits256_str(str,withtxid));
|
||||
char str[65],str2[65],*retstr; cJSON *retjson; bits256 txid;
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayscompletesigning",bits256_str(str,withtxid),coin,hex,"")) != 0 )
|
||||
{
|
||||
komodobroadcast(refcoin,acname,retjson);
|
||||
free_json(retjson);
|
||||
txid=komodobroadcast(refcoin,acname,retjson);
|
||||
free(retjson);
|
||||
return (txid);
|
||||
}
|
||||
else if ( retstr != 0 )
|
||||
{
|
||||
printf("error parsing gatewayscompletesigning.(%s)\n",retstr);
|
||||
free(retstr);
|
||||
}
|
||||
return (zeroid);
|
||||
}
|
||||
|
||||
void gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin)
|
||||
bits256 gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin)
|
||||
{
|
||||
char str[65],str2[65],*retstr; cJSON *retjson;
|
||||
printf("spend %s %s/v2 as marker\n",acname,bits256_str(str,withtxid));
|
||||
char str[65],str2[65],*retstr; cJSON *retjson; bits256 txid;
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysmarkdone",bits256_str(str,withtxid),coin,"","")) != 0 )
|
||||
{
|
||||
komodobroadcast(refcoin,acname,retjson);
|
||||
free_json(retjson);
|
||||
txid=komodobroadcast(refcoin,acname,retjson);
|
||||
free(retjson);
|
||||
return (txid);
|
||||
}
|
||||
else if ( retstr != 0 )
|
||||
{
|
||||
printf("error parsing gatewaysmarkdone.(%s)\n",retstr);
|
||||
free(retstr);
|
||||
}
|
||||
return (zeroid);
|
||||
}
|
||||
|
||||
int32_t get_gatewaysinfo(char *refcoin,char *acname,char *depositaddr,int32_t *Mp,int32_t *Np,char *bindtxidstr,char *coin,char *oraclestr, char **pubkeys)
|
||||
@@ -882,55 +864,9 @@ int32_t markerexists(char *refcoin,char *acname,char *coinaddr)
|
||||
free_json(array);
|
||||
}
|
||||
}
|
||||
fprintf(stderr,"Num=%d\n",num);
|
||||
return(num);
|
||||
|
||||
}
|
||||
int32_t markerfromthisnodeorunconfirmed(char *refcoin,char *acname,char *coinaddr)
|
||||
{
|
||||
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 )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
if ( (n= cJSON_GetArraySize(array)) != 0 )
|
||||
{
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
txid = jbits256i(array,i);
|
||||
if ( tx_has_voutaddress(refcoin,acname,txid,coinaddr) > 0 )
|
||||
{
|
||||
num = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
free_json(array);
|
||||
} else return(-1);
|
||||
}
|
||||
return(num);
|
||||
}
|
||||
|
||||
void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t M,int32_t N)
|
||||
{
|
||||
@@ -941,7 +877,9 @@ 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,K,retval,processed = 0; bits256 txid,cointxid,origtxid; int64_t satoshis;
|
||||
cJSON *retjson,*pending,*item,*clijson; char str[65],str1[65],str2[65],*rawtx,*coinstr,*txidaddr,*signeraddr,*depositaddr,*withdrawaddr;
|
||||
int32_t i,j,n,K,retval,processed = 0; bits256 txid,cointxid,withdrawtxid,lasttxid,completetxid; int64_t satoshis;
|
||||
|
||||
memset(&zeroid,0,sizeof(zeroid));
|
||||
if ( (retjson= get_gatewayspending("KMD",acname,bindtxidstr)) != 0 )
|
||||
{
|
||||
@@ -954,52 +892,55 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t
|
||||
if ( processed != 0 ) // avoid out of utxo conditions
|
||||
break;
|
||||
item = jitem(pending,i);
|
||||
origtxid = jbits256(item,"txid");
|
||||
withdrawtxid = jbits256(item,"withdrawtxid");
|
||||
//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 ( (txidaddr=jstr(item,"withdrawtxidaddr"))!= 0 && (withdrawaddr=jstr(item,"withdrawaddr")) != 0 && (depositaddr= jstr(item,"depositaddr")) != 0 && (signeraddr= jstr(item,"signeraddr")) != 0 )
|
||||
{
|
||||
if ( (satoshis= jdouble(item,"amount")*SATOSHIDEN) != 0 && is_cJSON_True(jobj(item,"confirmed_or_notarized")) != 0 && markerfromthisnodeorunconfirmed("KMD",acname,txidaddr) == 0)
|
||||
if ( (satoshis= jdouble(item,"amount")*SATOSHIDEN) != 0 && is_cJSON_True(jobj(item,"confirmed_or_notarized")) != 0)
|
||||
{
|
||||
if ( strcmp(depositaddr,signeraddr) == 0 )
|
||||
{
|
||||
rawtx = createrawtx(refcoin,"",depositaddr,withdrawaddr,txidaddr,satoshis);
|
||||
if ( rawtx != 0 )
|
||||
{
|
||||
if ( (clijson= addsignature(refcoin,"",rawtx)) != 0 && is_cJSON_True(jobj(clijson,"complete")) != 0)
|
||||
if ( (clijson=addsignature(refcoin,"",rawtx)) != 0 && is_cJSON_True(jobj(clijson,"complete")) != 0)
|
||||
{
|
||||
gatewayscompletesigning("KMD",acname,origtxid,refcoin,jstr(clijson,"hex"));
|
||||
fprintf(stderr,"withdraw %.8f %s to %s processed\n",(double)satoshis/SATOSHIDEN,refcoin,withdrawaddr);
|
||||
txid=gatewayscompletesigning("KMD",acname,withdrawtxid,refcoin,jstr(clijson,"hex"));
|
||||
if (txid.txid!=zeroid.txid) fprintf(stderr,"#WITHDRAW (%s) complete signing tx sent - %s\n",bits256_str(str,withdrawtxid),bits256_str(str1,txid));
|
||||
else fprintf(stderr,"error broadcasting tx on %s",acname);
|
||||
free_json(clijson);
|
||||
}
|
||||
processed++;
|
||||
processed++;
|
||||
}
|
||||
free(rawtx);
|
||||
} else fprintf(stderr,"couldnt create rawtx\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( (rawtx= get_gatewaysmultisig(refcoin,acname,txidaddr,&K)) == 0)
|
||||
lasttxid = jbits256(item,"last_txid");
|
||||
if ( lasttxid.txid==withdrawtxid.txid)
|
||||
{
|
||||
rawtx = createrawtx(refcoin,"",depositaddr,withdrawaddr,txidaddr,satoshis);
|
||||
}
|
||||
if ( rawtx != 0 )
|
||||
else rawtx=jstr(item,"hex");
|
||||
K=jint(item,"number_of_signs");
|
||||
if ( (clijson= addsignature(refcoin,"",rawtx)) != 0 )
|
||||
{
|
||||
if ( (clijson= addsignature(refcoin,"",rawtx)) != 0 )
|
||||
{
|
||||
if ( is_cJSON_True(jobj(clijson,"complete")) != 0 )
|
||||
{
|
||||
gatewayscompletesigning("KMD",acname,origtxid,refcoin,jstr(clijson,"hex"));
|
||||
fprintf(stderr,"withdraw %.8f %s M.%d N.%d to %s processed\n",(double)satoshis/SATOSHIDEN,refcoin,M,N,withdrawaddr);
|
||||
}
|
||||
else if ( jint(clijson,"partialtx") != 0 )
|
||||
{
|
||||
txid=gatewayspartialsign(refcoin,acname,origtxid,jstr(clijson,"hex"));
|
||||
fprintf(stderr,"%d sign(s) %dof%d partialtx %s sent\n",K+1,M,N,bits256_str(str,txid));
|
||||
}
|
||||
free_json(clijson);
|
||||
if ( is_cJSON_True(jobj(clijson,"complete")) != 0 )
|
||||
{
|
||||
txid=gatewayscompletesigning("KMD",acname,lasttxid,refcoin,jstr(clijson,"hex"));
|
||||
if (txid.txid!=zeroid.txid) fprintf(stderr,"#WITHDRAW (%s) complete signing tx (%dof%d) sent - %s\n",bits256_str(str,withdrawtxid),M,N,bits256_str(str1,txid));
|
||||
else fprintf(stderr,"error broadcasting tx on %s",acname);
|
||||
}
|
||||
else if ( jint(clijson,"partialtx") != 0 )
|
||||
{
|
||||
txid=gatewayspartialsign("KMD",acname,lasttxid,refcoin,jstr(clijson,"hex"));
|
||||
if (txid.txid!=zeroid.txid) fprintf(stderr,"#WITHDRAW (%s) partial tx (%d/%dof%d) sent - %s\n",bits256_str(str,withdrawtxid),K+1,M,N,bits256_str(str1,txid));
|
||||
else fprintf(stderr,"error broadcasting tx on %s",acname);
|
||||
}
|
||||
free_json(clijson);
|
||||
processed++;
|
||||
free(rawtx);
|
||||
} else fprintf(stderr,"couldnt create msig rawtx\n");
|
||||
}
|
||||
free(rawtx);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1012,24 +953,27 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t
|
||||
{
|
||||
if ( jint(retjson,"queueflag") != 0 && (coinstr= jstr(retjson,"coin")) != 0 && strcmp(coinstr,refcoin) == 0 )
|
||||
{
|
||||
if ( (pending=jarray(&n,retjson,"processed")) != 0 )
|
||||
if ((pending=jarray(&n,retjson,"processed")) != 0)
|
||||
{
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
item = jitem(pending,i);
|
||||
origtxid = jbits256(item,"txid");
|
||||
completetxid = jbits256(item,"completesigningtxid");
|
||||
txidaddr = jstr(item,"withdrawtxidaddr");
|
||||
withdrawtxid= jbits256(item,"withdrawtxid");
|
||||
double amount = jdouble(item,"amount");
|
||||
if (validateaddress(refcoin,"",txidaddr,"iswatchonly")==0 && validateaddress(refcoin,"",txidaddr,"ismine")==0)
|
||||
importaddress(refcoin,"",txidaddr,jstr(item,"txid"),0);
|
||||
if ( txidaddr != 0 && markerexists(refcoin,"",txidaddr)==0)
|
||||
importaddress(refcoin,"",txidaddr,jstr(item,"withdrawtxid"),0);
|
||||
if (txidaddr != 0 && markerexists(refcoin,"",txidaddr)==0)
|
||||
{
|
||||
cointxid = komodobroadcast(refcoin,"",item);
|
||||
if ( bits256_nonz(cointxid) != 0 )
|
||||
{
|
||||
withdrawaddr = jstr(item,"withdrawaddr");
|
||||
fprintf(stderr,"withdraw %.8f %s to %s - %s broadcasted on %s\n",(double)satoshis/SATOSHIDEN,refcoin,withdrawaddr,bits256_str(str,cointxid),refcoin);
|
||||
gatewaysmarkdone("KMD",acname,origtxid,refcoin);
|
||||
withdrawaddr = jstr(item,"withdrawaddr");
|
||||
txid=gatewaysmarkdone("KMD",acname,completetxid,refcoin);
|
||||
if (txid.txid!=zeroid.txid) fprintf(stderr,"#WITHDRAW (%s) markdone tx sent %s - %.8f %s to %s broadcasted on %s (%s)\n",bits256_str(str,withdrawtxid),bits256_str(str1,txid),amount,refcoin,withdrawaddr,refcoin,bits256_str(str2,cointxid));
|
||||
}
|
||||
else fprintf(stderr,"error broadcasting tx on %s",refcoin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1138,8 +1082,8 @@ int32_t main(int32_t argc,char **argv)
|
||||
}
|
||||
if (validateaddress(refcoin,"",depositaddr,"iswatchonly")==0 && validateaddress(refcoin,"",depositaddr,"ismine")==0)
|
||||
{
|
||||
if (M==N==1) importaddress(refcoin,"",depositaddr,bindtxidstr,0);
|
||||
else addmultisigaddress(refcoin,"",M,pubkeys,bindtxidstr);
|
||||
if (M==1 && N==1) importaddress(refcoin,"",depositaddr,bindtxidstr,0);
|
||||
else addmultisigaddress(refcoin,"",M,pubkeys);
|
||||
}
|
||||
if (pubkeys!=0) free(pubkeys);
|
||||
printf("set refcoin %s <- %s [%s] M.%d of N.%d\n",depositaddr,refcoin,REFCOIN_CLI,M,N);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
220
src/cc/heir.cpp
220
src/cc/heir.cpp
@@ -255,11 +255,11 @@ template <class Helper> int64_t IsHeirFundingVout(struct CCcontract_info* cp, co
|
||||
}
|
||||
|
||||
// makes coin initial tx opret
|
||||
CScript EncodeHeirCreateOpRet(uint8_t funcid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName)
|
||||
CScript EncodeHeirCreateOpRet(uint8_t funcid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, std::string memo)
|
||||
{
|
||||
uint8_t evalcode = EVAL_HEIR;
|
||||
|
||||
return CScript() << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << ownerPubkey << heirPubkey << inactivityTimeSec << heirName);
|
||||
return CScript() << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << ownerPubkey << heirPubkey << inactivityTimeSec << heirName << memo);
|
||||
}
|
||||
|
||||
// makes coin additional tx opret
|
||||
@@ -273,7 +273,7 @@ CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid, uint8_t hasHeirSpe
|
||||
|
||||
|
||||
// decode opret vout for Heir contract
|
||||
uint8_t _DecodeHeirOpRet(std::vector<uint8_t> vopret, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging)
|
||||
uint8_t _DecodeHeirOpRet(std::vector<uint8_t> vopret, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, std::string& memo, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging)
|
||||
{
|
||||
uint8_t evalCodeInOpret = 0;
|
||||
uint8_t heirFuncId = 0;
|
||||
@@ -287,13 +287,13 @@ uint8_t _DecodeHeirOpRet(std::vector<uint8_t> vopret, CPubKey& ownerPubkey, CPub
|
||||
uint8_t heirFuncId = 0;
|
||||
hasHeirSpendingBegun = 0;
|
||||
|
||||
bool result = E_UNMARSHAL(vopret, { ss >> evalCodeInOpret; ss >> heirFuncId; \
|
||||
if (heirFuncId == 'F') { \
|
||||
ss >> ownerPubkey; ss >> heirPubkey; ss >> inactivityTime; ss >> heirName; \
|
||||
} \
|
||||
else { \
|
||||
ss >> fundingTxidInOpret >> hasHeirSpendingBegun; \
|
||||
} \
|
||||
bool result = E_UNMARSHAL(vopret, { ss >> evalCodeInOpret; ss >> heirFuncId; \
|
||||
if (heirFuncId == 'F') { \
|
||||
ss >> ownerPubkey; ss >> heirPubkey; ss >> inactivityTime; ss >> heirName; ss >> memo; \
|
||||
} \
|
||||
else { \
|
||||
ss >> fundingTxidInOpret >> hasHeirSpendingBegun; \
|
||||
} \
|
||||
});
|
||||
|
||||
if (!result) {
|
||||
@@ -322,84 +322,49 @@ uint8_t _DecodeHeirOpRet(std::vector<uint8_t> vopret, CPubKey& ownerPubkey, CPub
|
||||
return (uint8_t)0;
|
||||
}
|
||||
|
||||
/* not used, see DecodeHeirOpRet(vopret,...)
|
||||
// overload for 'F' opret
|
||||
uint8_t DecodeHeirOpRet(CScript scriptPubKey, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging)
|
||||
{
|
||||
uint256 dummytxid;
|
||||
uint8_t dummyHasHeirSpendingBegun;
|
||||
std::vector<uint8_t> vopret;
|
||||
|
||||
GetOpReturnData(scriptPubKey, vopret);
|
||||
if (vopret.size() == 0) {
|
||||
if (!noLogging) std::cerr << "DecodeHeirOpRet() warning: empty opret" << std::endl;
|
||||
return (uint8_t)0;
|
||||
}
|
||||
return _DecodeHeirOpRet(vopret, ownerPubkey, heirPubkey, inactivityTime, heirName, dummytxid, dummyHasHeirSpendingBegun, noLogging);
|
||||
}*/
|
||||
|
||||
|
||||
/* not used, see DecodeHeirOpRet(vopret,...)
|
||||
// overload for A, C oprets and AddHeirContractInputs
|
||||
uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256& fundingtxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging)
|
||||
{
|
||||
CPubKey dummyOwnerPubkey, dummyHeirPubkey;
|
||||
int64_t dummyInactivityTime;
|
||||
std::string dummyHeirName;
|
||||
std::vector<uint8_t> vopret;
|
||||
|
||||
GetOpReturnData(scriptPubKey, vopret);
|
||||
if (vopret.size() == 0) {
|
||||
if (!noLogging) std::cerr << "DecodeHeirOpRet() warning: empty opret" << std::endl;
|
||||
return (uint8_t)0;
|
||||
}
|
||||
|
||||
return _DecodeHeirOpRet(vopret, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingtxidInOpret, hasHeirSpendingBegun, noLogging);
|
||||
} */
|
||||
|
||||
// decode combined opret:
|
||||
uint8_t _DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging)
|
||||
uint8_t _DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, std::string& memo, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging)
|
||||
{
|
||||
uint8_t evalCodeTokens = 0;
|
||||
std::vector<CPubKey> voutPubkeysDummy;
|
||||
std::vector<uint8_t> vopretExtra, vopretStripped;
|
||||
|
||||
if (DecodeTokenOpRet(scriptPubKey, evalCodeTokens, tokenid, voutPubkeysDummy, vopretExtra) != 0) {
|
||||
if (vopretExtra.size() > 1) {
|
||||
// restore the second opret:
|
||||
|
||||
if (!E_UNMARSHAL(vopretExtra, { ss >> vopretStripped; })) { //strip string size
|
||||
if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() could not unmarshal vopretStripped" << std::endl;
|
||||
return (uint8_t)0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() empty vopretExtra" << std::endl;
|
||||
return (uint8_t)0;
|
||||
}
|
||||
}
|
||||
else
|
||||
GetOpReturnData(scriptPubKey, vopretStripped);
|
||||
|
||||
return _DecodeHeirOpRet(vopretStripped, ownerPubkey, heirPubkey, inactivityTime, heirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging);
|
||||
uint8_t evalCodeTokens = 0;
|
||||
std::vector<CPubKey> voutPubkeysDummy;
|
||||
std::vector<uint8_t> vopretExtra, vopretStripped;
|
||||
|
||||
if (DecodeTokenOpRet(scriptPubKey, evalCodeTokens, tokenid, voutPubkeysDummy, vopretExtra) != 0) {
|
||||
if (vopretExtra.size() > 1) {
|
||||
// restore the second opret:
|
||||
|
||||
if (!E_UNMARSHAL(vopretExtra, { ss >> vopretStripped; })) { //strip string size
|
||||
if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() could not unmarshal vopretStripped" << std::endl;
|
||||
return (uint8_t)0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() empty vopretExtra" << std::endl;
|
||||
return (uint8_t)0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
GetOpReturnData(scriptPubKey, vopretStripped);
|
||||
}
|
||||
|
||||
return _DecodeHeirOpRet(vopretStripped, ownerPubkey, heirPubkey, inactivityTime, heirName, memo, fundingTxidInOpret, hasHeirSpendingBegun, noLogging);
|
||||
}
|
||||
|
||||
// overload to decode opret in fundingtxid:
|
||||
uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging) {
|
||||
uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, std::string& memo, bool noLogging) {
|
||||
uint256 dummyFundingTxidInOpret;
|
||||
uint8_t dummyHasHeirSpendingBegun;
|
||||
|
||||
return _DecodeHeirEitherOpRet(scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, dummyFundingTxidInOpret, dummyHasHeirSpendingBegun, noLogging);
|
||||
return _DecodeHeirEitherOpRet(scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, memo, dummyFundingTxidInOpret, dummyHasHeirSpendingBegun, noLogging);
|
||||
}
|
||||
|
||||
// overload to decode opret in A and C heir tx:
|
||||
uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, uint256 &fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) {
|
||||
CPubKey dummyOwnerPubkey, dummyHeirPubkey;
|
||||
int64_t dummyInactivityTime;
|
||||
std::string dummyHeirName;
|
||||
std::string dummyHeirName, dummyMemo;
|
||||
|
||||
return _DecodeHeirEitherOpRet(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging);
|
||||
return _DecodeHeirEitherOpRet(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, dummyMemo, fundingTxidInOpret, hasHeirSpendingBegun, noLogging);
|
||||
}
|
||||
|
||||
// check if pubkey is in vins
|
||||
@@ -423,7 +388,7 @@ void CheckVinPubkey(std::vector<CTxIn> vins, CPubKey pubkey, bool &hasPubkey, bo
|
||||
* find the latest funding tx: it may be the first F tx or one of A or C tx's
|
||||
* Note: this function is also called from validation code (use non-locking calls)
|
||||
*/
|
||||
uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, CScript& fundingOpretScript, uint8_t &hasHeirSpendingBegun)
|
||||
uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, std::string& memo, CScript& fundingOpretScript, uint8_t &hasHeirSpendingBegun)
|
||||
{
|
||||
CTransaction fundingtx;
|
||||
uint256 hashBlock;
|
||||
@@ -440,7 +405,7 @@ uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &toke
|
||||
if (myGetTransaction(fundingtxid, fundingtx, hashBlock) && fundingtx.vout.size()) {
|
||||
|
||||
CScript heirScript = (fundingtx.vout.size() > 0) ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript();
|
||||
uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true);
|
||||
uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, memo, true);
|
||||
if (funcId != 0) {
|
||||
// found at least funding tx!
|
||||
//std::cerr << "FindLatestFundingTx() lasttx currently is fundingtx, txid=" << fundingtxid.GetHex() << " opreturn type=" << (char)funcId << '\n';
|
||||
@@ -522,17 +487,17 @@ uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRe
|
||||
CPubKey ownerPubkey;
|
||||
CPubKey heirPubkey;
|
||||
int64_t inactivityTime;
|
||||
std::string heirName;
|
||||
std::string heirName, memo;
|
||||
|
||||
return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, opRetScript, hasHeirSpendingBegun);
|
||||
return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, memo, opRetScript, hasHeirSpendingBegun);
|
||||
}
|
||||
|
||||
// overload for transaction creation code
|
||||
uint256 FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint8_t &hasHeirSpendingBegun)
|
||||
uint256 FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, std::string& memo, uint8_t &hasHeirSpendingBegun)
|
||||
{
|
||||
CScript opRetScript;
|
||||
|
||||
return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, opRetScript, hasHeirSpendingBegun);
|
||||
return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, memo, opRetScript, hasHeirSpendingBegun);
|
||||
}
|
||||
|
||||
// add inputs of 1 of 2 cc address
|
||||
@@ -561,7 +526,7 @@ template <class Helper> int64_t Add1of2AddressInputs(struct CCcontract_info* cp,
|
||||
// no need to prevent dup
|
||||
// dimxy: maybe it is good to put tx's in cache?
|
||||
|
||||
std::cerr << "Add1of2AddressInputs() txid=" << txid.GetHex() << std::endl;
|
||||
//std::cerr << "Add1of2AddressInputs() txid=" << txid.GetHex() << std::endl;
|
||||
|
||||
if (GetTransaction(txid, heirtx, hashBlock, false) != 0) {
|
||||
uint256 tokenid;
|
||||
@@ -644,7 +609,7 @@ template <class Helper> int64_t LifetimeHeirContractFunds(struct CCcontract_info
|
||||
* and also for setting spending plan for the funds' owner and heir
|
||||
* @return fundingtxid handle for subsequent references to this heir funding plan
|
||||
*/
|
||||
template <typename Helper> UniValue _HeirFund(int64_t txfee, int64_t amount, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid)
|
||||
template <typename Helper> UniValue _HeirFund(int64_t txfee, int64_t amount, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string memo, uint256 tokenid)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ);
|
||||
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
|
||||
@@ -657,13 +622,7 @@ template <typename Helper> UniValue _HeirFund(int64_t txfee, int64_t amount, std
|
||||
int64_t markerfee = 10000;
|
||||
|
||||
//std::cerr << "HeirFund() amount=" << amount << " txfee=" << txfee << " heirPubkey IsValid()=" << heirPubkey.IsValid() << " inactivityTime(sec)=" << inactivityTimeSec << " tokenid=" << tokenid.GetHex() << std::endl;
|
||||
|
||||
if (!heirPubkey.IsValid()) {
|
||||
std::cerr << "HeirFund() heirPubkey is not valid!" << std::endl;
|
||||
result.push_back(Pair("result", "error"));
|
||||
result.push_back(Pair("error", "invalid heir pubkey"));
|
||||
}
|
||||
|
||||
|
||||
CPubKey myPubkey = pubkey2pk(Mypubkey());
|
||||
|
||||
if (AddNormalinputs(mtx, myPubkey, markerfee, 3) > 0) {
|
||||
@@ -711,10 +670,10 @@ template <typename Helper> UniValue _HeirFund(int64_t txfee, int64_t amount, std
|
||||
|
||||
// add change for txfee and opreturn vouts and sign tx:
|
||||
std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee,
|
||||
Helper::makeCreateOpRet(tokenid, voutTokenPubkeys, myPubkey, heirPubkey, inactivityTimeSec, heirName));
|
||||
Helper::makeCreateOpRet(tokenid, voutTokenPubkeys, myPubkey, heirPubkey, inactivityTimeSec, heirName, memo));
|
||||
if (!rawhextx.empty()) {
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hextx", rawhextx));
|
||||
result.push_back(Pair("hex", rawhextx));
|
||||
}
|
||||
else {
|
||||
std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl;
|
||||
@@ -737,12 +696,12 @@ template <typename Helper> UniValue _HeirFund(int64_t txfee, int64_t amount, std
|
||||
}
|
||||
|
||||
// if no these callers - it could not link
|
||||
UniValue HeirFundCoinCaller(int64_t txfee, int64_t satoshis, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid){
|
||||
return _HeirFund<CoinHelper>(txfee, satoshis, heirName, heirPubkey, inactivityTimeSec, tokenid);
|
||||
UniValue HeirFundCoinCaller(int64_t txfee, int64_t coins, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string memo){
|
||||
return _HeirFund<CoinHelper>(txfee, coins, heirName, heirPubkey, inactivityTimeSec, memo, zeroid);
|
||||
}
|
||||
|
||||
UniValue HeirFundTokenCaller(int64_t txfee, int64_t satoshis, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) {
|
||||
return _HeirFund<TokenHelper>(txfee, satoshis, heirName, heirPubkey, inactivityTimeSec, tokenid);
|
||||
UniValue HeirFundTokenCaller(int64_t txfee, int64_t satoshis, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string memo, uint256 tokenid) {
|
||||
return _HeirFund<TokenHelper>(txfee, satoshis, heirName, heirPubkey, inactivityTimeSec, memo, tokenid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -750,7 +709,7 @@ UniValue HeirFundTokenCaller(int64_t txfee, int64_t satoshis, std::string heirNa
|
||||
* creates tx to add more funds to cryptocondition address for spending by either funds' owner or heir
|
||||
* @return result object with raw tx or error text
|
||||
*/
|
||||
template <class Helper> UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, int64_t amount, uint256 latesttxid, uint8_t funcId, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, uint8_t hasHeirSpendingBegun)
|
||||
template <class Helper> UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, int64_t amount, uint256 latesttxid, uint8_t funcId, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, uint8_t hasHeirSpendingBegun)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ);
|
||||
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
|
||||
@@ -835,7 +794,7 @@ template <class Helper> UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, in
|
||||
Helper::makeAddOpRet(tokenid, voutTokenPubkeys, fundingtxid, hasHeirSpendingBegun)));
|
||||
|
||||
if (!rawhextx.empty()) {
|
||||
result.push_back(Pair("hextx", rawhextx));
|
||||
result.push_back(Pair("hex", rawhextx));
|
||||
}
|
||||
else {
|
||||
std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl;
|
||||
@@ -868,10 +827,10 @@ UniValue HeirAddCaller(uint256 fundingtxid, int64_t txfee, std::string strAmount
|
||||
|
||||
uint256 latesttxid, tokenid = zeroid;
|
||||
uint8_t funcId;
|
||||
std::string heirName;
|
||||
std::string heirName, memo;
|
||||
uint8_t hasHeirSpendingBegun = 0;
|
||||
|
||||
if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) {
|
||||
if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, memo, hasHeirSpendingBegun)) != zeroid) {
|
||||
if (tokenid == zeroid) {
|
||||
int64_t amount = (int64_t)(atof(strAmount.c_str()) * COIN);
|
||||
if (amount <= 0) {
|
||||
@@ -880,8 +839,7 @@ UniValue HeirAddCaller(uint256 fundingtxid, int64_t txfee, std::string strAmount
|
||||
result.push_back(Pair("error", "invalid amount"));
|
||||
return result;
|
||||
}
|
||||
|
||||
return _HeirAdd<CoinHelper>(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun);
|
||||
return _HeirAdd<CoinHelper>(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, hasHeirSpendingBegun);
|
||||
}
|
||||
else {
|
||||
int64_t amount = atoll(strAmount.c_str());
|
||||
@@ -891,7 +849,7 @@ UniValue HeirAddCaller(uint256 fundingtxid, int64_t txfee, std::string strAmount
|
||||
result.push_back(Pair("error", "invalid amount"));
|
||||
return result;
|
||||
}
|
||||
return _HeirAdd<TokenHelper>(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun);
|
||||
return _HeirAdd<TokenHelper>(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, hasHeirSpendingBegun);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -910,7 +868,7 @@ UniValue HeirAddCaller(uint256 fundingtxid, int64_t txfee, std::string strAmount
|
||||
* creates tx to spend funds from cryptocondition address by either funds' owner or heir
|
||||
* @return result object with raw tx or error text
|
||||
*/
|
||||
template <typename Helper>UniValue _HeirClaim(uint256 fundingtxid, int64_t txfee, int64_t amount, uint256 latesttxid, uint8_t funcId, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, uint8_t hasHeirSpendingBegun)
|
||||
template <typename Helper>UniValue _HeirClaim(uint256 fundingtxid, int64_t txfee, int64_t amount, uint256 latesttxid, uint8_t funcId, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, uint8_t hasHeirSpendingBegun)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ);
|
||||
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
|
||||
@@ -1008,7 +966,7 @@ template <typename Helper>UniValue _HeirClaim(uint256 fundingtxid, int64_t txfee
|
||||
|
||||
if (!rawhextx.empty()) {
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hextx", rawhextx));
|
||||
result.push_back(Pair("hex", rawhextx));
|
||||
}
|
||||
else {
|
||||
std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl;
|
||||
@@ -1038,10 +996,10 @@ UniValue HeirClaimCaller(uint256 fundingtxid, int64_t txfee, std::string strAmou
|
||||
|
||||
uint256 latesttxid, tokenid = zeroid;
|
||||
uint8_t funcId;
|
||||
std::string heirName;
|
||||
std::string heirName, memo;
|
||||
uint8_t hasHeirSpendingBegun = 0;
|
||||
|
||||
if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) {
|
||||
if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, memo, hasHeirSpendingBegun)) != zeroid) {
|
||||
if (tokenid == zeroid) {
|
||||
int64_t amount = (int64_t)(atof(strAmount.c_str()) * COIN);
|
||||
if (amount < 0) {
|
||||
@@ -1050,7 +1008,7 @@ UniValue HeirClaimCaller(uint256 fundingtxid, int64_t txfee, std::string strAmou
|
||||
result.push_back(Pair("error", "invalid amount"));
|
||||
return result;
|
||||
}
|
||||
return _HeirClaim<CoinHelper>(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun);
|
||||
return _HeirClaim<CoinHelper>(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, hasHeirSpendingBegun);
|
||||
}
|
||||
else {
|
||||
int64_t amount = atoll(strAmount.c_str());
|
||||
@@ -1060,7 +1018,7 @@ UniValue HeirClaimCaller(uint256 fundingtxid, int64_t txfee, std::string strAmou
|
||||
result.push_back(Pair("error", "invalid amount"));
|
||||
return result;
|
||||
}
|
||||
return _HeirClaim<TokenHelper>(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun);
|
||||
return _HeirClaim<TokenHelper>(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, hasHeirSpendingBegun);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1099,7 +1057,7 @@ UniValue HeirInfo(uint256 fundingtxid)
|
||||
|
||||
CPubKey ownerPubkey, heirPubkey;
|
||||
uint256 dummyTokenid, tokenid = zeroid; // important to clear tokenid
|
||||
std::string heirName;
|
||||
std::string heirName, memo;
|
||||
int64_t inactivityTimeSec;
|
||||
const bool noLogging = false;
|
||||
uint8_t funcId;
|
||||
@@ -1118,7 +1076,7 @@ UniValue HeirInfo(uint256 fundingtxid)
|
||||
|
||||
uint8_t hasHeirSpendingBegun = 0;
|
||||
|
||||
uint256 latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun);
|
||||
uint256 latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, memo, hasHeirSpendingBegun);
|
||||
|
||||
if (latestFundingTxid != zeroid) {
|
||||
int32_t numblocks;
|
||||
@@ -1159,12 +1117,22 @@ UniValue HeirInfo(uint256 fundingtxid)
|
||||
else
|
||||
total = LifetimeHeirContractFunds<TokenHelper>(cp, fundingtxid, ownerPubkey, heirPubkey);
|
||||
|
||||
msg = "type";
|
||||
if (tokenid == zeroid) {
|
||||
stream << "coins";
|
||||
}
|
||||
else {
|
||||
stream << "tokens";
|
||||
}
|
||||
result.push_back(Pair(msg, stream.str().c_str()));
|
||||
stream.str("");
|
||||
stream.clear();
|
||||
|
||||
msg = "lifetime";
|
||||
if (tokenid == zeroid) {
|
||||
msg = "funding total in coins";
|
||||
stream << std::fixed << std::setprecision(8) << (double)total / COIN;
|
||||
}
|
||||
else {
|
||||
msg = "funding total in tokens";
|
||||
stream << total;
|
||||
}
|
||||
result.push_back(Pair(msg, stream.str().c_str()));
|
||||
@@ -1177,12 +1145,11 @@ UniValue HeirInfo(uint256 fundingtxid)
|
||||
else
|
||||
inputs = Add1of2AddressInputs<TokenHelper>(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, 0, 60);
|
||||
|
||||
msg = "available";
|
||||
if (tokenid == zeroid) {
|
||||
msg = "funding available in coins";
|
||||
stream << std::fixed << std::setprecision(8) << (double)inputs / COIN;
|
||||
}
|
||||
else {
|
||||
msg = "funding available in tokens";
|
||||
stream << inputs;
|
||||
}
|
||||
result.push_back(Pair(msg, stream.str().c_str()));
|
||||
@@ -1192,14 +1159,14 @@ UniValue HeirInfo(uint256 fundingtxid)
|
||||
if (tokenid != zeroid) {
|
||||
int64_t ownerInputs = TokenHelper::addOwnerInputs(tokenid, mtx, ownerPubkey, 0, (int32_t)64);
|
||||
stream << ownerInputs;
|
||||
msg = "owner funding available in tokens";
|
||||
msg = "OwnerRemainderTokens";
|
||||
result.push_back(Pair(msg, stream.str().c_str()));
|
||||
stream.str("");
|
||||
stream.clear();
|
||||
}
|
||||
|
||||
stream << inactivityTimeSec;
|
||||
result.push_back(Pair("inactivity time setting, sec", stream.str().c_str()));
|
||||
result.push_back(Pair("InactivityTimeSetting", stream.str().c_str()));
|
||||
stream.str("");
|
||||
stream.clear();
|
||||
|
||||
@@ -1209,18 +1176,20 @@ UniValue HeirInfo(uint256 fundingtxid)
|
||||
}
|
||||
|
||||
stream << std::boolalpha << (hasHeirSpendingBegun || durationSec > inactivityTimeSec);
|
||||
result.push_back(Pair("spending allowed for the heir", stream.str().c_str()));
|
||||
result.push_back(Pair("IsHeirSpendingAllowed", stream.str().c_str()));
|
||||
stream.str("");
|
||||
stream.clear();
|
||||
|
||||
// adding owner current inactivity time:
|
||||
if (!hasHeirSpendingBegun && durationSec <= inactivityTimeSec) {
|
||||
stream << durationSec;
|
||||
result.push_back(Pair("owner inactivity time, sec", stream.str().c_str()));
|
||||
result.push_back(Pair("InactivityTime", stream.str().c_str()));
|
||||
stream.str("");
|
||||
stream.clear();
|
||||
}
|
||||
|
||||
|
||||
result.push_back(Pair("memo", memo.c_str()));
|
||||
|
||||
result.push_back(Pair("result", "success"));
|
||||
}
|
||||
else {
|
||||
@@ -1262,18 +1231,18 @@ void _HeirList(struct CCcontract_info *cp, UniValue &result)
|
||||
CTransaction fundingtx;
|
||||
if (GetTransaction(txid, fundingtx, hashBlock, false)) {
|
||||
CPubKey ownerPubkey, heirPubkey;
|
||||
std::string heirName;
|
||||
std::string heirName, memo;
|
||||
int64_t inactivityTimeSec;
|
||||
const bool noLogging = true;
|
||||
uint256 tokenid;
|
||||
|
||||
CScript opret = (fundingtx.vout.size() > 0) ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript();
|
||||
uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, true);
|
||||
uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, memo, true);
|
||||
|
||||
// note: if it is not Heir token funcId would be equal to 0
|
||||
if (funcId == 'F') {
|
||||
//result.push_back(Pair("fundingtxid kind name", txid.GetHex() + std::string(" ") + (typeid(Helper) == typeid(TokenHelper) ? std::string("token") : std::string("coin")) + std::string(" ") + heirName));
|
||||
result.push_back( Pair("fundingtxid", txid.GetHex()) );
|
||||
result.push_back( txid.GetHex() );
|
||||
}
|
||||
else {
|
||||
std::cerr << "HeirList() this is not the initial F transaction=" << txid.GetHex() << std::endl;
|
||||
@@ -1288,17 +1257,14 @@ void _HeirList(struct CCcontract_info *cp, UniValue &result)
|
||||
|
||||
UniValue HeirList()
|
||||
{
|
||||
UniValue result(UniValue::VOBJ);
|
||||
result.push_back(Pair("result", "success"));
|
||||
UniValue result(UniValue::VARR);
|
||||
//result.push_back(Pair("result", "success"));
|
||||
//result.push_back(Pair("name", "Heir List"));
|
||||
|
||||
struct CCcontract_info *cpHeir, *cpTokens, heirC, tokenC; // NOTE we must use a separate 'C' structure for each CCinit!
|
||||
struct CCcontract_info *cpHeir, heirC;
|
||||
|
||||
cpHeir = CCinit(&heirC, EVAL_HEIR);
|
||||
//cpTokens = CCinit(&tokenC, EVAL_TOKENS);
|
||||
|
||||
_HeirList(cpHeir, result);
|
||||
//_HeirList<TokenHelper>(cpTokens, result); not used anymore
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
#define IS_CHARINSTR(c, str) (std::string(str).find((char)(c)) != std::string::npos)
|
||||
|
||||
// makes coin initial tx opret
|
||||
CScript EncodeHeirCreateOpRet(uint8_t funcid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName);
|
||||
CScript EncodeHeirCreateOpRet(uint8_t funcid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, std::string memo);
|
||||
CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid, uint8_t isHeirSpendingBegan);
|
||||
|
||||
uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRetScript, uint8_t &isHeirSpendingBegan);
|
||||
//uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256& fundingtxid, uint8_t &isHeirSpendingBegan, bool noLogging = false);
|
||||
//uint8_t DecodeHeirOpRet(CScript scriptPubKey, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging = false);
|
||||
uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging = false);
|
||||
uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, std::string& memo, bool noLogging = false);
|
||||
uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, uint256 &fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging = false);
|
||||
|
||||
inline static bool isMyFuncId(uint8_t funcid) { return IS_CHARINSTR(funcid, "FAC"); }
|
||||
@@ -28,8 +28,8 @@ public:
|
||||
return AddNormalinputs(mtx, ownerPubkey, total, maxinputs);
|
||||
}
|
||||
|
||||
static CScript makeCreateOpRet(uint256 dummyid, std::vector<CPubKey> dummyPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) {
|
||||
return EncodeHeirCreateOpRet((uint8_t)'F', ownerPubkey, heirPubkey, inactivityTimeSec, heirName);
|
||||
static CScript makeCreateOpRet(uint256 dummyid, std::vector<CPubKey> dummyPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, std::string memo) {
|
||||
return EncodeHeirCreateOpRet((uint8_t)'F', ownerPubkey, heirPubkey, inactivityTimeSec, heirName, memo);
|
||||
}
|
||||
static CScript makeAddOpRet(uint256 dummyid, std::vector<CPubKey> dummyPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) {
|
||||
return EncodeHeirOpRet((uint8_t)'A', fundingtxid, isHeirSpendingBegan);
|
||||
@@ -66,9 +66,9 @@ public:
|
||||
return AddTokenCCInputs(cpHeir, mtx, ownerPubkey, tokenid, total, maxinputs);
|
||||
}
|
||||
|
||||
static CScript makeCreateOpRet(uint256 tokenid, std::vector<CPubKey> voutTokenPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) {
|
||||
static CScript makeCreateOpRet(uint256 tokenid, std::vector<CPubKey> voutTokenPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, std::string memo) {
|
||||
return EncodeTokenOpRet(tokenid, voutTokenPubkeys,
|
||||
EncodeHeirCreateOpRet((uint8_t)'F', ownerPubkey, heirPubkey, inactivityTimeSec, heirName));
|
||||
EncodeHeirCreateOpRet((uint8_t)'F', ownerPubkey, heirPubkey, inactivityTimeSec, heirName, memo));
|
||||
}
|
||||
static CScript makeAddOpRet(uint256 tokenid, std::vector<CPubKey> voutTokenPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) {
|
||||
return EncodeTokenOpRet(tokenid, voutTokenPubkeys,
|
||||
@@ -407,10 +407,10 @@ public:
|
||||
//std::cerr << "CCC1of2AddressValidator::validateVout() entered" << std::endl;
|
||||
CPubKey ownerPubkey, heirPubkey;
|
||||
int64_t inactivityTime;
|
||||
std::string heirName;
|
||||
std::string heirName, memo;
|
||||
uint256 tokenid;
|
||||
|
||||
uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true);
|
||||
uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, memo, true);
|
||||
if (funcId == 0) {
|
||||
message = m_customMessage + std::string(" invalid opreturn format");
|
||||
std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl;
|
||||
@@ -462,13 +462,13 @@ public:
|
||||
|
||||
CPubKey ownerPubkey, heirPubkey;
|
||||
int64_t inactivityTime;
|
||||
std::string heirName;
|
||||
std::string heirName, memo;
|
||||
uint256 tokenid;
|
||||
|
||||
///std::cerr << "CMyPubkeyVoutValidator::validateVout() m_opRetScript=" << m_opRetScript.ToString() << std::endl;
|
||||
|
||||
// get both pubkeys:
|
||||
uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true);
|
||||
uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, memo, true);
|
||||
if (funcId == 0) {
|
||||
message = std::string("invalid opreturn format");
|
||||
return false;
|
||||
@@ -522,11 +522,11 @@ public:
|
||||
|
||||
CPubKey ownerPubkey, heirPubkey;
|
||||
int64_t inactivityTime;
|
||||
std::string heirName;
|
||||
std::string heirName, memo;
|
||||
uint256 tokenid;
|
||||
|
||||
// get heir pubkey:
|
||||
uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true);
|
||||
uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, memo, true);
|
||||
if (funcId == 0) {
|
||||
message = std::string("invalid opreturn format");
|
||||
return false;
|
||||
|
||||
@@ -478,9 +478,9 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "gateways", "gatewayspartialsign", &gatewayspartialsign, true },
|
||||
{ "gateways", "gatewayscompletesigning", &gatewayscompletesigning, true },
|
||||
{ "gateways", "gatewaysmarkdone", &gatewaysmarkdone, true },
|
||||
{ "gateways", "gatewayspending", &gatewayspending, true },
|
||||
{ "gateways", "gatewayspendingdeposits", &gatewayspendingdeposits, true },
|
||||
{ "gateways", "gatewayspendingwithdraws", &gatewayspendingwithdraws, true },
|
||||
{ "gateways", "gatewaysprocessed", &gatewaysprocessed, true },
|
||||
{ "gateways", "gatewaysmultisig", &gatewaysmultisig, true },
|
||||
|
||||
// dice
|
||||
{ "dice", "dicelist", &dicelist, true },
|
||||
|
||||
@@ -300,9 +300,9 @@ extern UniValue gatewayswithdraw(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewayspartialsign(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewayscompletesigning(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewaysmarkdone(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewayspending(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewayspendingdeposits(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewayspendingwithdraws(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewaysprocessed(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewaysmultisig(const UniValue& params, bool fHelp);
|
||||
extern UniValue channelslist(const UniValue& params, bool fHelp);
|
||||
extern UniValue channelsinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue channelsopen(const UniValue& params, bool fHelp);
|
||||
|
||||
@@ -6263,11 +6263,23 @@ UniValue gatewaysmarkdone(const UniValue& params, bool fHelp)
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue gatewayspending(const UniValue& params, bool fHelp)
|
||||
UniValue gatewayspendingdeposits(const UniValue& params, bool fHelp)
|
||||
{
|
||||
uint256 bindtxid; std::string coin;
|
||||
if ( fHelp || params.size() != 2 )
|
||||
throw runtime_error("gatewayspending bindtxid coin\n");
|
||||
throw runtime_error("gatewayspendingdeposits bindtxid coin\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");
|
||||
bindtxid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
coin = params[1].get_str();
|
||||
return(GatewaysPendingDeposits(bindtxid,coin));
|
||||
}
|
||||
|
||||
UniValue gatewayspendingwithdraws(const UniValue& params, bool fHelp)
|
||||
{
|
||||
uint256 bindtxid; std::string coin;
|
||||
if ( fHelp || params.size() != 2 )
|
||||
throw runtime_error("gatewayspendingwithdraws bindtxid coin\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");
|
||||
bindtxid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
@@ -6287,19 +6299,6 @@ UniValue gatewaysprocessed(const UniValue& params, bool fHelp)
|
||||
return(GatewaysProcessedWithdraws(bindtxid,coin));
|
||||
}
|
||||
|
||||
UniValue gatewaysmultisig(const UniValue& params, bool fHelp)
|
||||
{
|
||||
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);
|
||||
txidaddr = (char *)params[0].get_str().c_str();
|
||||
return(GatewaysMultisig(txidaddr));
|
||||
}
|
||||
|
||||
UniValue oracleslist(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if ( fHelp || params.size() > 0 )
|
||||
@@ -7368,13 +7367,13 @@ UniValue heirfund(const UniValue& params, bool fHelp)
|
||||
int64_t inactivitytime;
|
||||
std::string hex;
|
||||
std::vector<unsigned char> pubkey;
|
||||
std::string name;
|
||||
std::string name, memo;
|
||||
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size() != 5 && params.size() != 6)
|
||||
throw runtime_error("heirfund txfee funds heirname heirpubkey inactivitytime [tokenid]\n");
|
||||
if (fHelp || params.size() != 6 && params.size() != 7)
|
||||
throw runtime_error("heirfund txfee funds heirname heirpubkey inactivitytime memo [tokenid]\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");
|
||||
|
||||
@@ -7382,36 +7381,53 @@ UniValue heirfund(const UniValue& params, bool fHelp)
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
||||
txfee = atoll(params[0].get_str().c_str());
|
||||
if (txfee < 0)
|
||||
throw runtime_error("incorrect txfee param\n");
|
||||
if (txfee < 0) {
|
||||
result.push_back(Pair("result", "error"));
|
||||
result.push_back(Pair("error", "incorrect txfee"));
|
||||
return result;
|
||||
}
|
||||
|
||||
if(params.size() == 6) // tokens in satoshis:
|
||||
if(params.size() == 7) // tokens in satoshis:
|
||||
amount = atoll(params[1].get_str().c_str());
|
||||
else // coins:
|
||||
amount = atof(params[1].get_str().c_str()) * COIN;
|
||||
|
||||
if( amount <= 0 )
|
||||
throw runtime_error("incorrect amount\n");
|
||||
if (amount <= 0) {
|
||||
result.push_back(Pair("result", "error"));
|
||||
result.push_back(Pair("error", "incorrect amount"));
|
||||
return result;
|
||||
}
|
||||
|
||||
name = params[2].get_str();
|
||||
|
||||
pubkey = ParseHex(params[3].get_str().c_str());
|
||||
if( !pubkey2pk(pubkey).IsValid() )
|
||||
throw runtime_error("incorrect pubkey\n");
|
||||
if (!pubkey2pk(pubkey).IsValid()) {
|
||||
result.push_back(Pair("result", "error"));
|
||||
result.push_back(Pair("error", "incorrect pubkey"));
|
||||
return result;
|
||||
}
|
||||
|
||||
inactivitytime = atoll(params[4].get_str().c_str());
|
||||
if (inactivitytime <= 0)
|
||||
throw runtime_error("incorrect inactivity time param\n");
|
||||
if (inactivitytime <= 0) {
|
||||
result.push_back(Pair("result", "error"));
|
||||
result.push_back(Pair("error", "incorrect inactivity time"));
|
||||
return result;
|
||||
}
|
||||
|
||||
if (params.size() == 6) {
|
||||
tokenid = Parseuint256((char*)params[5].get_str().c_str());
|
||||
if(tokenid == zeroid)
|
||||
throw runtime_error("incorrect tokenid\n");
|
||||
memo = params[5].get_str();
|
||||
|
||||
if (params.size() == 7) {
|
||||
tokenid = Parseuint256((char*)params[6].get_str().c_str());
|
||||
if (tokenid == zeroid) {
|
||||
result.push_back(Pair("result", "error"));
|
||||
result.push_back(Pair("error", "incorrect tokenid"));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if( tokenid == zeroid )
|
||||
result = HeirFundCoinCaller(txfee, amount, name, pubkey2pk(pubkey), inactivitytime, zeroid);
|
||||
result = HeirFundCoinCaller(txfee, amount, name, pubkey2pk(pubkey), inactivitytime, memo);
|
||||
else
|
||||
result = HeirFundTokenCaller(txfee, amount, name, pubkey2pk(pubkey), inactivitytime, tokenid);
|
||||
result = HeirFundTokenCaller(txfee, amount, name, pubkey2pk(pubkey), inactivitytime, memo, tokenid);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -7439,8 +7455,11 @@ UniValue heiradd(const UniValue& params, bool fHelp)
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
||||
txfee = atoll(params[0].get_str().c_str());
|
||||
if (txfee < 0)
|
||||
throw runtime_error("incorrect txfee param\n");
|
||||
if (txfee < 0) {
|
||||
result.push_back(Pair("result", "error"));
|
||||
result.push_back(Pair("error", "incorrect txfee"));
|
||||
return result;
|
||||
}
|
||||
|
||||
fundingtxid = Parseuint256((char*)params[2].get_str().c_str());
|
||||
|
||||
@@ -7450,7 +7469,7 @@ UniValue heiradd(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue heirclaim(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result; // result(UniValue::VOBJ);
|
||||
UniValue result;
|
||||
uint256 fundingtxid;
|
||||
int64_t txfee;
|
||||
int64_t inactivitytime;
|
||||
@@ -7458,7 +7477,6 @@ UniValue heirclaim(const UniValue& params, bool fHelp)
|
||||
std::vector<unsigned char> pubkey;
|
||||
std::string name;
|
||||
|
||||
// do we need this?
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return NullUniValue;
|
||||
|
||||
@@ -7471,8 +7489,11 @@ UniValue heirclaim(const UniValue& params, bool fHelp)
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
||||
txfee = atoll(params[0].get_str().c_str());
|
||||
if (txfee < 0)
|
||||
throw runtime_error("incorrect txfee param\n");
|
||||
if (txfee < 0) {
|
||||
result.push_back(Pair("result", "error"));
|
||||
result.push_back(Pair("error", "incorrect txfee"));
|
||||
return result;
|
||||
}
|
||||
|
||||
fundingtxid = Parseuint256((char*)params[2].get_str().c_str());
|
||||
|
||||
@@ -7483,8 +7504,9 @@ UniValue heirclaim(const UniValue& params, bool fHelp)
|
||||
UniValue heirinfo(const UniValue& params, bool fHelp)
|
||||
{
|
||||
uint256 fundingtxid;
|
||||
if (fHelp || params.size() != 1) // or 0?
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error("heirinfo fundingtxid\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");
|
||||
|
||||
@@ -7494,7 +7516,7 @@ UniValue heirinfo(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue heirlist(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0) // or 0?
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error("heirlist\n");
|
||||
|
||||
// if ( ensure_CCrequirements() < 0 )
|
||||
|
||||
Reference in New Issue
Block a user