Merge branch 'FSM' into jl777

# Conflicts:
#	src/cc/CCinclude.h
#	src/cc/CCtokens.cpp
#	src/cc/CCtx.cpp
#	src/wallet/rpcwallet.cpp
This commit is contained in:
jl777
2019-02-11 13:56:09 -11:00
12 changed files with 407 additions and 176 deletions

View File

@@ -336,6 +336,84 @@ bool CBitcoinAddress::IsScript() const
return IsValid() && vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS); return IsValid() && vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS);
} }
bool CCustomBitcoinAddress::Set(const CKeyID& id)
{
SetData(base58Prefixes[0], &id, 20);
return true;
}
bool CCustomBitcoinAddress::Set(const CPubKey& key)
{
CKeyID id = key.GetID();
SetData(base58Prefixes[0], &id, 20);
return true;
}
bool CCustomBitcoinAddress::Set(const CScriptID& id)
{
SetData(base58Prefixes[1], &id, 20);
return true;
}
bool CCustomBitcoinAddress::Set(const CTxDestination& dest)
{
return boost::apply_visitor(CBitcoinAddressVisitor(this), dest);
}
bool CCustomBitcoinAddress::IsValid() const
{
bool fCorrectSize = vchData.size() == 20;
bool fKnownVersion = vchVersion == base58Prefixes[0] ||
vchVersion == base58Prefixes[1];
return fCorrectSize && fKnownVersion;
}
bool CCustomBitcoinAddress::GetKeyID(CKeyID& keyID) const
{
if (!IsValid() || vchVersion != base58Prefixes[0])
return false;
uint160 id;
memcpy(&id, &vchData[0], 20);
keyID = CKeyID(id);
return true;
}
CTxDestination CCustomBitcoinAddress::Get() const
{
if (!IsValid())
return CNoDestination();
uint160 id;
memcpy(&id, &vchData[0], 20);
if (vchVersion == base58Prefixes[0])
return CKeyID(id);
else if (vchVersion == base58Prefixes[1])
return CScriptID(id);
else
return CNoDestination();
}
bool CCustomBitcoinAddress::GetIndexKey(uint160& hashBytes, int& type) const
{
if (!IsValid()) {
return false;
} else if (vchVersion == base58Prefixes[0]) {
memcpy(&hashBytes, &vchData[0], 20);
type = 1;
return true;
} else if (vchVersion == base58Prefixes[1]) {
memcpy(&hashBytes, &vchData[0], 20);
type = 2;
return true;
}
return false;
}
bool CCustomBitcoinAddress::IsScript() const
{
return IsValid() && vchVersion == base58Prefixes[1];
}
void CBitcoinSecret::SetKey(const CKey& vchSecret) void CBitcoinSecret::SetKey(const CKey& vchSecret)
{ {
assert(vchSecret.IsValid()); assert(vchSecret.IsValid());

View File

@@ -130,9 +130,9 @@ public:
*/ */
class CBitcoinAddress : public CBase58Data { class CBitcoinAddress : public CBase58Data {
public: public:
bool Set(const CKeyID &id); virtual bool Set(const CKeyID &id);
bool Set(const CPubKey &key); virtual bool Set(const CPubKey &key);
bool Set(const CScriptID &id); virtual bool Set(const CScriptID &id);
bool Set(const CTxDestination &dest); bool Set(const CTxDestination &dest);
bool IsValid() const; bool IsValid() const;
bool IsValid(const CChainParams &params) const; bool IsValid(const CChainParams &params) const;
@@ -151,6 +151,31 @@ public:
bool IsScript() const; bool IsScript() const;
}; };
class CCustomBitcoinAddress : public CBitcoinAddress {
std::vector<unsigned char> base58Prefixes[2];
public:
bool Set(const CKeyID &id);
bool Set(const CPubKey &key);
bool Set(const CScriptID &id);
bool Set(const CTxDestination &dest);
bool IsValid() const;
CCustomBitcoinAddress() {}
CCustomBitcoinAddress(const CTxDestination &dest,uint8_t taddr,uint8_t pubkey_prefix,uint8_t script_prefix)
{
if (taddr!=0) base58Prefixes[0].push_back(taddr);
base58Prefixes[0].push_back(pubkey_prefix);
base58Prefixes[1].push_back(script_prefix);
Set(dest);
}
CTxDestination Get() const;
bool GetKeyID(CKeyID &keyID) const;
bool GetKeyID_NoCheck(CKeyID& keyID) const;
bool GetIndexKey(uint160& hashBytes, int& type) const;
bool IsScript() const;
};
/** /**
* A base58-encoded secret key * A base58-encoded secret key
*/ */

View File

@@ -21,7 +21,7 @@
#include "../merkleblock.h" #include "../merkleblock.h"
bool GatewaysValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); bool GatewaysValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn);
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 GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector<CPubKey> pubkeys,uint8_t p1,uint8_t p2,uint8_t p3,uint8_t p4);
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 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 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,CPubKey withdrawpub,int64_t amount); std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,CPubKey withdrawpub,int64_t amount);
@@ -34,6 +34,8 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin);
// CCcustom // CCcustom
UniValue GatewaysInfo(uint256 bindtxid); UniValue GatewaysInfo(uint256 bindtxid);
UniValue GatewaysExternalAddress(uint256 bindtxid,CPubKey pubkey);
UniValue GatewaysDumpPrivKey(uint256 bindtxid,CKey privkey);
UniValue GatewaysList(); UniValue GatewaysList();
#endif #endif

View File

@@ -161,6 +161,7 @@ int32_t iguana_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t *
CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys); CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys);
int64_t CCaddress_balance(char *coinaddr); int64_t CCaddress_balance(char *coinaddr);
CPubKey CCtxidaddr(char *txidaddr,uint256 txid); CPubKey CCtxidaddr(char *txidaddr,uint256 txid);
CPubKey CCCustomtxidaddr(char *txidaddr,uint256 txid,uint8_t taddr,uint8_t prefix,uint8_t prefix2);
bool GetCCParams(Eval* eval, const CTransaction &tx, uint32_t nIn, bool GetCCParams(Eval* eval, const CTransaction &tx, uint32_t nIn,
CTransaction &txOut, std::vector<std::vector<unsigned char>> &preConditions, std::vector<std::vector<unsigned char>> &params); CTransaction &txOut, std::vector<std::vector<unsigned char>> &preConditions, std::vector<std::vector<unsigned char>> &params);
@@ -237,6 +238,7 @@ bool GetCCaddress1of2(struct CCcontract_info *cp,char *destaddr,CPubKey pk,CPubK
bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,int64_t nValue); bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,int64_t nValue);
bool PreventCC(Eval* eval,const CTransaction &tx,int32_t preventCCvins,int32_t numvins,int32_t preventCCvouts,int32_t numvouts); bool PreventCC(Eval* eval,const CTransaction &tx,int32_t preventCCvins,int32_t numvins,int32_t preventCCvouts,int32_t numvouts);
bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey);
bool GetCustomscriptaddress(char *destaddr,const CScript &scriptPubKey,uint8_t taddr,uint8_t prefix,uint8_t prefix2);
std::vector<uint8_t> Mypubkey(); std::vector<uint8_t> Mypubkey();
bool Myprivkey(uint8_t myprivkey[]); bool Myprivkey(uint8_t myprivkey[]);
int64_t CCduration(int32_t &numblocks,uint256 txid); int64_t CCduration(int32_t &numblocks,uint256 txid);

View File

@@ -300,6 +300,18 @@ bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey)
return(false); return(false);
} }
bool GetCustomscriptaddress(char *destaddr,const CScript &scriptPubKey,uint8_t taddr,uint8_t prefix, uint8_t prefix2)
{
CTxDestination address; txnouttype whichType;
if ( ExtractDestination(scriptPubKey,address) != 0 )
{
strcpy(destaddr,(char *)CCustomBitcoinAddress(address,taddr,prefix,prefix2).ToString().c_str());
return(true);
}
//fprintf(stderr,"ExtractDestination failed\n");
return(false);
}
bool GetCCParams(Eval* eval, const CTransaction &tx, uint32_t nIn, bool GetCCParams(Eval* eval, const CTransaction &tx, uint32_t nIn,
CTransaction &txOut, std::vector<std::vector<unsigned char>> &preConditions, std::vector<std::vector<unsigned char>> &params) CTransaction &txOut, std::vector<std::vector<unsigned char>> &preConditions, std::vector<std::vector<unsigned char>> &params)
{ {
@@ -360,6 +372,16 @@ CPubKey CCtxidaddr(char *txidaddr,uint256 txid)
return(pk); return(pk);
} }
CPubKey CCCustomtxidaddr(char *txidaddr,uint256 txid,uint8_t taddr,uint8_t prefix,uint8_t prefix2)
{
uint8_t buf33[33]; CPubKey pk;
buf33[0] = 0x02;
endiancpy(&buf33[1],(uint8_t *)&txid,32);
pk = buf2pk(buf33);
GetCustomscriptaddress(txidaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG,taddr,prefix,prefix2);
return(pk);
}
bool _GetCCaddress(char *destaddr,uint8_t evalcode,CPubKey pk) bool _GetCCaddress(char *destaddr,uint8_t evalcode,CPubKey pk)
{ {
CC *payoutCond; CC *payoutCond;

View File

@@ -312,22 +312,20 @@ uint64_t get_btcusd()
char *REFCOIN_CLI; char *REFCOIN_CLI;
cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char *arg0,char *arg1,char *arg2,char *arg3) cJSON *get_cli(char *refcoin,char **retstrp,char *acname,char *method,char *arg0,char *arg1,char *arg2,char *arg3)
{ {
long fsize; cJSON *retjson = 0; char cmdstr[32768],*jsonstr,fname[256]; long fsize; cJSON *retjson = 0; char cmdstr[32768],*jsonstr,fname[256];
sprintf(fname,"/tmp/oraclefeed.%s",method); sprintf(fname,"/tmp/oraclefeed.%s",method);
if ( acname[0] != 0 ) if ( acname[0] != 0 )
{ {
if ( refcoin[0] != 0 && strcmp(refcoin,"KMD") != 0 ) if ( refcoin[0] == 0 )
printf("unexpected: refcoin.(%s) acname.(%s)\n",refcoin,acname); printf("must supply reference coin\n");
sprintf(cmdstr,"./komodo-cli -ac_name=%s %s %s %s %s %s > %s 2>/tmp/oraclefeed.error\n",acname,method,arg0,arg1,arg2,arg3,fname); sprintf(cmdstr,"./komodo-cli -ac_name=%s %s %s %s %s %s > %s 2>/tmp/oraclefeed.error\n",acname,method,arg0,arg1,arg2,arg3,fname);
} }
else if ( strcmp(refcoin,"KMD") == 0 )
sprintf(cmdstr,"./komodo-cli %s %s %s %s %s > %s 2>/tmp/oraclefeed.error\n",method,arg0,arg1,arg2,arg3,fname);
else if ( REFCOIN_CLI != 0 && REFCOIN_CLI[0] != 0 ) else if ( REFCOIN_CLI != 0 && REFCOIN_CLI[0] != 0 )
{ {
sprintf(cmdstr,"%s %s %s %s %s %s > %s 2>/tmp/oraclefeed.error\n",REFCOIN_CLI,method,arg0,arg1,arg2,arg3,fname); sprintf(cmdstr,"%s %s %s %s %s %s > %s 2>/tmp/oraclefeed.error\n",REFCOIN_CLI,method,arg0,arg1,arg2,arg3,fname);
printf("ref.(%s) REFCOIN_CLI (%s)\n",refcoin,cmdstr); //printf("ref.(%s) REFCOIN_CLI (%s)\n",refcoin,cmdstr);
} }
#ifdef TESTMODE #ifdef TESTMODE
fprintf(stderr,"cmd: %s\n",cmdstr); fprintf(stderr,"cmd: %s\n",cmdstr);
@@ -349,13 +347,13 @@ cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char
return(retjson); return(retjson);
} }
bits256 komodobroadcast(char *refcoin,char *acname,cJSON *hexjson) bits256 broadcasttx(char *refcoin,char *acname,cJSON *hexjson)
{ {
char *hexstr,*retstr,str[65]; cJSON *retjson; bits256 txid; char *hexstr,*retstr,str[65]; cJSON *retjson; bits256 txid;
memset(txid.bytes,0,sizeof(txid)); memset(txid.bytes,0,sizeof(txid));
if ( (hexstr= jstr(hexjson,"hex")) != 0 ) if ( (hexstr= jstr(hexjson,"hex")) != 0 )
{ {
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"sendrawtransaction",hexstr,"","","")) != 0 ) if ( (retjson= get_cli(refcoin,&retstr,acname,"sendrawtransaction",hexstr,"","","")) != 0 )
{ {
if (strcmp("error",jstr(retjson,"result"))==0) printf("%s\n",jstr(retjson,"error")); if (strcmp("error",jstr(retjson,"result"))==0) printf("%s\n",jstr(retjson,"error"));
free_json(retjson); free_json(retjson);
@@ -374,36 +372,14 @@ bits256 komodobroadcast(char *refcoin,char *acname,cJSON *hexjson)
return(txid); return(txid);
} }
bits256 sendtoaddress(char *refcoin,char *acname,char *destaddr,int64_t satoshis)
{
char numstr[32],*retstr,str[65]; cJSON *retjson; bits256 txid;
memset(txid.bytes,0,sizeof(txid));
sprintf(numstr,"%.8f",(double)satoshis/SATOSHIDEN);
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"sendtoaddress",destaddr,numstr,"","")) != 0 )
{
fprintf(stderr,"unexpected sendrawtransaction json.(%s)\n",jprint(retjson,0));
free_json(retjson);
}
else if ( retstr != 0 )
{
if ( strlen(retstr) >= 64 )
{
retstr[64] = 0;
decode_hex(txid.bytes,32,retstr);
}
fprintf(stderr,"sendtoaddress %s %.8f txid.(%s)\n",destaddr,(double)satoshis/SATOSHIDEN,bits256_str(str,txid));
free(retstr);
}
return(txid);
}
int32_t get_coinheight(char *refcoin,char *acname) int32_t get_coinheight(char *refcoin,char *acname)
{ {
cJSON *retjson; char *retstr; int32_t height=0; cJSON *retjson; char *retstr; int32_t height=0;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockchaininfo","","","","")) != 0 ) if ( (retjson= get_cli(refcoin,&retstr,acname,"getblockchaininfo","","","","")) != 0 )
{ {
height = jint(retjson,"blocks"); height = jint(retjson,"blocks");
free_json(retjson); free_json(retjson);
} }
else if ( retstr != 0 ) else if ( retstr != 0 )
{ {
@@ -418,7 +394,7 @@ bits256 get_coinblockhash(char *refcoin,char *acname,int32_t height)
cJSON *retjson; char *retstr,heightstr[32]; bits256 hash; cJSON *retjson; char *retstr,heightstr[32]; bits256 hash;
memset(hash.bytes,0,sizeof(hash)); memset(hash.bytes,0,sizeof(hash));
sprintf(heightstr,"%d",height); sprintf(heightstr,"%d",height);
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockhash",heightstr,"","","")) != 0 ) if ( (retjson= get_cli(refcoin,&retstr,acname,"getblockhash",heightstr,"","","")) != 0 )
{ {
fprintf(stderr,"unexpected blockhash json.(%s)\n",jprint(retjson,0)); fprintf(stderr,"unexpected blockhash json.(%s)\n",jprint(retjson,0));
free_json(retjson); free_json(retjson);
@@ -439,7 +415,7 @@ bits256 get_coinmerkleroot(char *refcoin,char *acname,bits256 blockhash)
{ {
cJSON *retjson; char *retstr,str[65]; bits256 merkleroot; cJSON *retjson; char *retstr,str[65]; bits256 merkleroot;
memset(merkleroot.bytes,0,sizeof(merkleroot)); memset(merkleroot.bytes,0,sizeof(merkleroot));
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockheader",bits256_str(str,blockhash),"","","")) != 0 ) if ( (retjson= get_cli(refcoin,&retstr,acname,"getblockheader",bits256_str(str,blockhash),"","","")) != 0 )
{ {
merkleroot = jbits256(retjson,"merkleroot"); merkleroot = jbits256(retjson,"merkleroot");
//fprintf(stderr,"got merkleroot.(%s)\n",bits256_str(str,merkleroot)); //fprintf(stderr,"got merkleroot.(%s)\n",bits256_str(str,merkleroot));
@@ -477,7 +453,7 @@ int32_t get_coinheader(char *refcoin,char *acname,bits256 *blockhashp,bits256 *m
cJSON *get_gatewayspending(char *refcoin,char *acname,char *bindtxidstr) cJSON *get_gatewayspending(char *refcoin,char *acname,char *bindtxidstr)
{ {
cJSON *retjson; char *retstr; cJSON *retjson; char *retstr;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspendingwithdraws",bindtxidstr,refcoin,"","")) != 0 ) if ( (retjson= get_cli(refcoin,&retstr,acname,"gatewayspendingwithdraws",bindtxidstr,refcoin,"","")) != 0 )
{ {
//printf("pending.(%s)\n",jprint(retjson,0)); //printf("pending.(%s)\n",jprint(retjson,0));
return(retjson); return(retjson);
@@ -493,7 +469,7 @@ cJSON *get_gatewayspending(char *refcoin,char *acname,char *bindtxidstr)
cJSON *get_gatewaysprocessed(char *refcoin,char *acname,char *bindtxidstr) cJSON *get_gatewaysprocessed(char *refcoin,char *acname,char *bindtxidstr)
{ {
cJSON *retjson; char *retstr; cJSON *retjson; char *retstr;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysprocessed",bindtxidstr,refcoin,"","")) != 0 ) if ( (retjson= get_cli(refcoin,&retstr,acname,"gatewaysprocessed",bindtxidstr,refcoin,"","")) != 0 )
{ {
//printf("pending.(%s)\n",jprint(retjson,0)); //printf("pending.(%s)\n",jprint(retjson,0));
return(retjson); return(retjson);
@@ -509,7 +485,7 @@ cJSON *get_gatewaysprocessed(char *refcoin,char *acname,char *bindtxidstr)
cJSON *get_rawmempool(char *refcoin,char *acname) cJSON *get_rawmempool(char *refcoin,char *acname)
{ {
cJSON *retjson; char *retstr; cJSON *retjson; char *retstr;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getrawmempool","","","","")) != 0 ) if ( (retjson= get_cli(refcoin,&retstr,acname,"getrawmempool","","","","")) != 0 )
{ {
//printf("mempool.(%s)\n",jprint(retjson,0)); //printf("mempool.(%s)\n",jprint(retjson,0));
return(retjson); return(retjson);
@@ -528,7 +504,7 @@ cJSON *get_addressutxos(char *refcoin,char *acname,char *coinaddr)
if ( refcoin[0] != 0 && strcmp(refcoin,"KMD") != 0 ) if ( refcoin[0] != 0 && strcmp(refcoin,"KMD") != 0 )
printf("warning: assumes %s has addressindex enabled\n",refcoin); printf("warning: assumes %s has addressindex enabled\n",refcoin);
sprintf(jsonbuf,"{\\\"addresses\\\":[\\\"%s\\\"]}",coinaddr); sprintf(jsonbuf,"{\\\"addresses\\\":[\\\"%s\\\"]}",coinaddr);
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getaddressutxos",jsonbuf,"","","")) != 0 ) if ( (retjson= get_cli(refcoin,&retstr,acname,"getaddressutxos",jsonbuf,"","","")) != 0 )
{ {
//printf("addressutxos.(%s)\n",jprint(retjson,0)); //printf("addressutxos.(%s)\n",jprint(retjson,0));
return(retjson); return(retjson);
@@ -544,7 +520,7 @@ cJSON *get_addressutxos(char *refcoin,char *acname,char *coinaddr)
cJSON *get_rawtransaction(char *refcoin,char *acname,bits256 txid) cJSON *get_rawtransaction(char *refcoin,char *acname,bits256 txid)
{ {
cJSON *retjson; char *retstr,str[65]; cJSON *retjson; char *retstr,str[65];
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getrawtransaction",bits256_str(str,txid),"1","","")) != 0 ) if ( (retjson= get_cli(refcoin,&retstr,acname,"getrawtransaction",bits256_str(str,txid),"1","","")) != 0 )
{ {
return(retjson); return(retjson);
} }
@@ -559,7 +535,7 @@ cJSON *get_rawtransaction(char *refcoin,char *acname,bits256 txid)
int32_t validateaddress(char *refcoin,char *acname,char *depositaddr, char* compare) int32_t validateaddress(char *refcoin,char *acname,char *depositaddr, char* compare)
{ {
cJSON *retjson; char *retstr; int32_t res=0; cJSON *retjson; char *retstr; int32_t res=0;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"validateaddress",depositaddr,"","","")) != 0 ) if ( (retjson= get_cli(refcoin,&retstr,acname,"validateaddress",depositaddr,"","","")) != 0 )
{ {
if (is_cJSON_True(jobj(retjson,compare)) != 0 ) res=1; if (is_cJSON_True(jobj(retjson,compare)) != 0 ) res=1;
free_json(retjson); free_json(retjson);
@@ -578,7 +554,7 @@ void importaddress(char *refcoin,char *acname,char *depositaddr, char *label,int
cJSON *retjson; char *retstr; char rescanstr[10]; cJSON *retjson; char *retstr; char rescanstr[10];
if (rescan) strcpy(rescanstr,"true"); if (rescan) strcpy(rescanstr,"true");
else strcpy(rescanstr,"false"); else strcpy(rescanstr,"false");
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"importaddress",depositaddr,label,rescanstr,"")) != 0 ) if ( (retjson= get_cli(refcoin,&retstr,acname,"importaddress",depositaddr,label,rescanstr,"")) != 0 )
{ {
printf("importaddress.(%s)\n",jprint(retjson,0)); printf("importaddress.(%s)\n",jprint(retjson,0));
free_json(retjson); free_json(retjson);
@@ -595,7 +571,7 @@ void addmultisigaddress(char *refcoin,char *acname,int32_t M, char *pubkeys)
cJSON *retjson; char *retstr,Mstr[10],addr[64]; cJSON *retjson; char *retstr,Mstr[10],addr[64];
sprintf(Mstr,"%d",M); sprintf(Mstr,"%d",M);
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"addmultisigaddress",Mstr,pubkeys,"","")) != 0 ) if ( (retjson= get_cli(refcoin,&retstr,acname,"addmultisigaddress",Mstr,pubkeys,"","")) != 0 )
{ {
fprintf(stderr,"unexpected addmultisigaddress json.(%s)\n",jprint(retjson,0)); fprintf(stderr,"unexpected addmultisigaddress json.(%s)\n",jprint(retjson,0));
free(retstr); free(retstr);
@@ -603,7 +579,7 @@ void addmultisigaddress(char *refcoin,char *acname,int32_t M, char *pubkeys)
else if ( retstr != 0 ) else if ( retstr != 0 )
{ {
sprintf(addr,"\"%s\"",retstr); sprintf(addr,"\"%s\"",retstr);
get_komodocli(refcoin,&retstr,acname,"importaddress",addr,"\"\"","false",""); get_cli(refcoin,&retstr,acname,"importaddress",addr,"\"\"","false","");
printf("addmultisigaddress.(%s)\n",retstr); printf("addmultisigaddress.(%s)\n",retstr);
free_json(retjson); free_json(retjson);
} }
@@ -644,11 +620,11 @@ char *createrawtx(char *refcoin,char *acname,char *depositaddr,char *withdrawadd
else txfee = 10000; else txfee = 10000;
if ( satoshis < txfee ) if ( satoshis < txfee )
{ {
printf("createrawtx satoshis %.8f < txfee %.8f\n",(double)satoshis/SATOSHIDEN,(double)txfee/SATOSHIDEN); printf("createrawtx: satoshis %.8f < txfee %.8f\n",(double)satoshis/SATOSHIDEN,(double)txfee/SATOSHIDEN);
return(0); return(0);
} }
sprintf(array,"\'[\"%s\"]\'",depositaddr); sprintf(array,"\'[\"%s\"]\'",depositaddr);
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"listunspent","1","99999999",array,"")) != 0 ) if ( (retjson= get_cli(refcoin,&retstr,acname,"listunspent","1","99999999",array,"")) != 0 )
{ {
//createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,...} //createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,...}
if ( (vins= getinputarray(&total,retjson,satoshis)) != 0 ) if ( (vins= getinputarray(&total,retjson,satoshis)) != 0 )
@@ -669,7 +645,7 @@ char *createrawtx(char *refcoin,char *acname,char *depositaddr,char *withdrawadd
char *argB=malloc(sizeof(char) * (strlen(tmpB)+3)); char *argB=malloc(sizeof(char) * (strlen(tmpB)+3));
sprintf(argA,"\'%s\'",tmpA); sprintf(argA,"\'%s\'",tmpA);
sprintf(argB,"\'%s\'",tmpB); sprintf(argB,"\'%s\'",tmpB);
if ( (retjson2= get_komodocli(refcoin,&txstr,acname,"createrawtransaction",argA,argB,"","")) != 0 ) if ( (retjson2= get_cli(refcoin,&txstr,acname,"createrawtransaction",argA,argB,"","")) != 0 )
{ {
printf("createrawtx: unexpected JSON2.(%s)\n",jprint(retjson2,0)); printf("createrawtx: unexpected JSON2.(%s)\n",jprint(retjson2,0));
free_json(retjson2); free_json(retjson2);
@@ -697,7 +673,7 @@ char *createrawtx(char *refcoin,char *acname,char *depositaddr,char *withdrawadd
cJSON *addsignature(char *refcoin,char *acname,char *rawtx, int M) cJSON *addsignature(char *refcoin,char *acname,char *rawtx, int M)
{ {
char *retstr,*hexstr; cJSON *retjson; char *retstr,*hexstr; cJSON *retjson;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"signrawtransaction",rawtx,"","","")) != 0 ) if ( (retjson= get_cli(refcoin,&retstr,acname,"signrawtransaction",rawtx,"","","")) != 0 )
{ {
if ( is_cJSON_True(jobj(retjson,"complete")) != 0 ) if ( is_cJSON_True(jobj(retjson,"complete")) != 0 )
return(retjson); return(retjson);
@@ -716,12 +692,12 @@ cJSON *addsignature(char *refcoin,char *acname,char *rawtx, int M)
return(0); return(0);
} }
bits256 gatewayspartialsign(char *refcoin,char *acname,bits256 txid,char *coin,char *hex) bits256 gatewayspartialsign(char *refcoin,char *acname,bits256 txid,char *hex)
{ {
char str[65],*retstr; cJSON *retjson; char str[65],*retstr; cJSON *retjson;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspartialsign",bits256_str(str,txid),coin,hex,"")) != 0 ) if ( (retjson= get_cli(refcoin,&retstr,acname,"gatewayspartialsign",bits256_str(str,txid),refcoin,hex,"")) != 0 )
{ {
if (strcmp("error",jstr(retjson,"result"))!=0) txid=komodobroadcast(refcoin,acname,retjson); if (strcmp("error",jstr(retjson,"result"))!=0) txid=broadcasttx(refcoin,acname,retjson);
else printf("%s\n",jstr(retjson,"error")); else printf("%s\n",jstr(retjson,"error"));
free(retjson); free(retjson);
return (txid); return (txid);
@@ -734,12 +710,12 @@ bits256 gatewayspartialsign(char *refcoin,char *acname,bits256 txid,char *coin,c
return (zeroid); return (zeroid);
} }
bits256 gatewayscompletesigning(char *refcoin,char *acname,bits256 withtxid,char *coin,char *hex) bits256 gatewayscompletesigning(char *refcoin,char *acname,bits256 withtxid,char *hex)
{ {
char str[65],*retstr; cJSON *retjson; bits256 txid; char str[65],*retstr; cJSON *retjson; bits256 txid;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayscompletesigning",bits256_str(str,withtxid),coin,hex,"")) != 0 ) if ( (retjson= get_cli(refcoin,&retstr,acname,"gatewayscompletesigning",bits256_str(str,withtxid),refcoin,hex,"")) != 0 )
{ {
if (strcmp("error",jstr(retjson,"result"))!=0) txid=komodobroadcast(refcoin,acname,retjson); if (strcmp("error",jstr(retjson,"result"))!=0) txid=broadcasttx(refcoin,acname,retjson);
else printf("%s\n",jstr(retjson,"error")); else printf("%s\n",jstr(retjson,"error"));
free(retjson); free(retjson);
return (txid); return (txid);
@@ -752,12 +728,12 @@ bits256 gatewayscompletesigning(char *refcoin,char *acname,bits256 withtxid,char
return (zeroid); return (zeroid);
} }
bits256 gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin) bits256 gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid)
{ {
char str[65],str2[65],*retstr; cJSON *retjson; bits256 txid; char str[65],str2[65],*retstr; cJSON *retjson; bits256 txid;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysmarkdone",bits256_str(str,withtxid),coin,"","")) != 0 ) if ( (retjson= get_cli(refcoin,&retstr,acname,"gatewaysmarkdone",bits256_str(str,withtxid),refcoin,"","")) != 0 )
{ {
if (strcmp("error",jstr(retjson,"result"))!=0) txid=komodobroadcast(refcoin,acname,retjson); if (strcmp("error",jstr(retjson,"result"))!=0) txid=broadcasttx(refcoin,acname,retjson);
else printf("%s\n",jstr(retjson,"error")); else printf("%s\n",jstr(retjson,"error"));
free(retjson); free(retjson);
return (txid); return (txid);
@@ -773,7 +749,7 @@ bits256 gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin)
int32_t get_gatewaysinfo(char *refcoin,char *acname,char *depositaddr,int32_t *Mp,int32_t *Np,char *bindtxidstr,char *coin,char *oraclestr, char **pubkeys) 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,temp[128]; cJSON *retjson,*pubarray; int32_t n; char *oracle,*retstr,*name,*deposit,temp[128]; cJSON *retjson,*pubarray; int32_t n;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysinfo",bindtxidstr,"","","")) != 0 ) if ( (retjson= get_cli(refcoin,&retstr,acname,"gatewaysinfo",bindtxidstr,"","","")) != 0 )
{ {
if ( (oracle= jstr(retjson,"oracletxid")) != 0 && strcmp(oracle,oraclestr) == 0 && (deposit= jstr(retjson,"deposit")) != 0 ) if ( (oracle= jstr(retjson,"oracletxid")) != 0 && strcmp(oracle,oraclestr) == 0 && (deposit= jstr(retjson,"deposit")) != 0 )
{ {
@@ -888,7 +864,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t
int32_t i,j,n,K,retval,processed = 0; bits256 txid,cointxid,withdrawtxid,lasttxid,completetxid; int64_t satoshis; int32_t i,j,n,K,retval,processed = 0; bits256 txid,cointxid,withdrawtxid,lasttxid,completetxid; int64_t satoshis;
memset(&zeroid,0,sizeof(zeroid)); memset(&zeroid,0,sizeof(zeroid));
if ( (retjson= get_gatewayspending("KMD",acname,bindtxidstr)) != 0 ) if ( (retjson= get_gatewayspending(refcoin,acname,bindtxidstr)) != 0 )
{ {
if ( jint(retjson,"queueflag") != 0 && (coinstr= jstr(retjson,"coin")) != 0 && strcmp(coinstr,refcoin) == 0 ) if ( jint(retjson,"queueflag") != 0 && (coinstr= jstr(retjson,"coin")) != 0 && strcmp(coinstr,refcoin) == 0 )
{ {
@@ -912,9 +888,9 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t
{ {
if ( (clijson=addsignature(refcoin,"",rawtx,M)) != 0 && is_cJSON_True(jobj(clijson,"complete")) != 0) if ( (clijson=addsignature(refcoin,"",rawtx,M)) != 0 && is_cJSON_True(jobj(clijson,"complete")) != 0)
{ {
txid=gatewayscompletesigning("KMD",acname,withdrawtxid,refcoin,jstr(clijson,"hex")); txid=gatewayscompletesigning(refcoin,acname,withdrawtxid,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)); if (txid.txid!=zeroid.txid) fprintf(stderr,"### SIGNING withdraw %s 1of1\n",bits256_str(str,withdrawtxid));
else fprintf(stderr,"error broadcasting tx on %s",acname); else fprintf(stderr,"### SIGNING error broadcasting tx on %s",acname);
free_json(clijson); free_json(clijson);
processed++; processed++;
} }
@@ -934,13 +910,13 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t
{ {
if ( is_cJSON_True(jobj(clijson,"complete")) != 0 ) if ( is_cJSON_True(jobj(clijson,"complete")) != 0 )
{ {
txid=gatewayscompletesigning("KMD",acname,lasttxid,refcoin,jstr(clijson,"hex")); txid=gatewayscompletesigning(refcoin,acname,lasttxid,jstr(clijson,"hex"));
if (txid.txid!=zeroid.txid) fprintf(stderr,"### SIGNING withdraw %s %dof%d\n",bits256_str(str,withdrawtxid),K+1,N); if (txid.txid!=zeroid.txid) fprintf(stderr,"### SIGNING withdraw %s %dof%d\n",bits256_str(str,withdrawtxid),K+1,N);
else fprintf(stderr,"### SIGNING error broadcasting tx on %s\n",acname); else fprintf(stderr,"### SIGNING error broadcasting tx on %s\n",acname);
} }
else if ( jint(clijson,"partialtx") != 0 ) else if ( jint(clijson,"partialtx") != 0 )
{ {
txid=gatewayspartialsign("KMD",acname,lasttxid,refcoin,jstr(clijson,"hex")); txid=gatewayspartialsign(refcoin,acname,lasttxid,jstr(clijson,"hex"));
if (txid.txid!=zeroid.txid) fprintf(stderr,"### SIGNING withdraw %s %d/%dof%d\n",bits256_str(str,withdrawtxid),K+1,M,N); if (txid.txid!=zeroid.txid) fprintf(stderr,"### SIGNING withdraw %s %d/%dof%d\n",bits256_str(str,withdrawtxid),K+1,M,N);
else fprintf(stderr,"### SIGNING error broadcasting tx on %s\n",acname); else fprintf(stderr,"### SIGNING error broadcasting tx on %s\n",acname);
} }
@@ -956,7 +932,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t
} }
free_json(retjson); free_json(retjson);
} }
if ( (retjson= get_gatewaysprocessed("KMD",acname,bindtxidstr)) != 0 ) if ( (retjson= get_gatewaysprocessed(refcoin,acname,bindtxidstr)) != 0 )
{ {
if ( jint(retjson,"queueflag") != 0 && (coinstr= jstr(retjson,"coin")) != 0 && strcmp(coinstr,refcoin) == 0 ) if ( jint(retjson,"queueflag") != 0 && (coinstr= jstr(retjson,"coin")) != 0 && strcmp(coinstr,refcoin) == 0 )
{ {
@@ -973,13 +949,14 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t
importaddress(refcoin,"",txidaddr,jstr(item,"withdrawtxid"),0); importaddress(refcoin,"",txidaddr,jstr(item,"withdrawtxid"),0);
if (is_cJSON_True(jobj(item,"confirmed_or_notarized")) && txidaddr != 0 && markerexists(refcoin,"",txidaddr)==0) if (is_cJSON_True(jobj(item,"confirmed_or_notarized")) && txidaddr != 0 && markerexists(refcoin,"",txidaddr)==0)
{ {
cointxid = komodobroadcast(refcoin,"",item); cointxid = broadcasttx(refcoin,"",item);
if ( bits256_nonz(cointxid) != 0 ) if ( bits256_nonz(cointxid) != 0 )
{ {
withdrawaddr = jstr(item,"withdrawaddr"); withdrawaddr = jstr(item,"withdrawaddr");
fprintf(stderr,"### WITHDRAW %.8f %s sent to %s\n",amount,refcoin,withdrawaddr); fprintf(stderr,"### WITHDRAW %.8f %s sent to %s\n",amount,refcoin,withdrawaddr);
txid=gatewaysmarkdone("KMD",acname,completetxid,refcoin); txid=gatewaysmarkdone(refcoin,acname,completetxid);
if (txid.txid!=zeroid.txid) fprintf(stderr,"### MARKDONE withdraw %s\n",bits256_str(str,withdrawtxid)); if (txid.txid!=zeroid.txid) fprintf(stderr,"### MARKDONE withdraw %s\n",bits256_str(str,withdrawtxid));
else fprintf(stderr,"### MARKDONE error broadcasting tx on %s\n",refcoin);
} }
else fprintf(stderr,"### WITHDRAW error broadcasting tx on %s\n",refcoin); else fprintf(stderr,"### WITHDRAW error broadcasting tx on %s\n",refcoin);
} }
@@ -1073,7 +1050,7 @@ int32_t main(int32_t argc,char **argv)
while ( 1 ) while ( 1 )
{ {
retstr = 0; retstr = 0;
if ( (refcoin[0] == 0 || prevheight < (get_coinheight(refcoin,"") - 10)) && (clijson= get_komodocli("KMD",&retstr,acname,"oraclesinfo",oraclestr,"","","")) != 0 ) if ( (refcoin[0] == 0 || prevheight < (get_coinheight(refcoin,"") - 10)) && (clijson= get_cli(refcoin,&retstr,acname,"oraclesinfo",oraclestr,"","","")) != 0 )
{ {
if ( refcoin[0] == 0 && jstr(clijson,"name") != 0 ) if ( refcoin[0] == 0 && jstr(clijson,"name") != 0 )
{ {
@@ -1084,7 +1061,7 @@ int32_t main(int32_t argc,char **argv)
exit(0); exit(0);
} }
pubkeys=0; pubkeys=0;
if ( get_gatewaysinfo("KMD",acname,depositaddr,&M,&N,bindtxidstr,refcoin,oraclestr,&pubkeys) < 0 ) if ( get_gatewaysinfo(refcoin,acname,depositaddr,&M,&N,bindtxidstr,refcoin,oraclestr,&pubkeys) < 0 )
{ {
printf("cant find bindtxid.(%s)\n",bindtxidstr); printf("cant find bindtxid.(%s)\n",bindtxidstr);
exit(0); exit(0);
@@ -1106,10 +1083,9 @@ int32_t main(int32_t argc,char **argv)
{ {
if ( (height= get_oracledata(refcoin,"",prevheight,hexstr,sizeof(hexstr),"Ihh")) != 0 ) if ( (height= get_oracledata(refcoin,"",prevheight,hexstr,sizeof(hexstr),"Ihh")) != 0 )
{ {
if ( (clijson2= get_komodocli("KMD",&retstr2,acname,"oraclesdata",oraclestr,hexstr,"","")) != 0 ) if ( (clijson2= get_cli(refcoin,&retstr2,acname,"oraclesdata",oraclestr,hexstr,"","")) != 0 )
{ {
//printf("data.(%s)\n",jprint(clijson2,0)); txid = broadcasttx(refcoin,acname,clijson2);
txid = komodobroadcast("KMD",acname,clijson2);
if ( bits256_nonz(txid) != 0 ) if ( bits256_nonz(txid) != 0 )
{ {
prevheight = height; prevheight = height;

View File

@@ -14,6 +14,7 @@
******************************************************************************/ ******************************************************************************/
#include "CCGateways.h" #include "CCGateways.h"
#include "key_io.h"
/* /*
prevent duplicate bindtxid via mempool scan prevent duplicate bindtxid via mempool scan
@@ -147,7 +148,12 @@
*/ */
// start of consensus code // start of consensus code
CScript EncodeGatewaysBindOpRet(uint8_t funcid,uint256 tokenid,std::string coin,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector<CPubKey> gatewaypubkeys,uint8_t taddr,uint8_t prefix,uint8_t prefix2) #define KMD_PUBTYPE 60
#define KMD_P2SHTYPE 85
#define KMD_WIFTYPE 188
#define KMD_TADDR 0
CScript EncodeGatewaysBindOpRet(uint8_t funcid,uint256 tokenid,std::string coin,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector<CPubKey> gatewaypubkeys,uint8_t taddr,uint8_t prefix,uint8_t prefix2,uint8_t wiftype)
{ {
CScript opret; uint8_t evalcode = EVAL_GATEWAYS; struct CCcontract_info *cp,C; CPubKey gatewayspk; CScript opret; uint8_t evalcode = EVAL_GATEWAYS; struct CCcontract_info *cp,C; CPubKey gatewayspk;
std::vector<CPubKey> pubkeys; std::vector<CPubKey> pubkeys;
@@ -155,11 +161,11 @@ CScript EncodeGatewaysBindOpRet(uint8_t funcid,uint256 tokenid,std::string coin,
cp = CCinit(&C,EVAL_GATEWAYS); cp = CCinit(&C,EVAL_GATEWAYS);
gatewayspk = GetUnspendable(cp,0); gatewayspk = GetUnspendable(cp,0);
pubkeys.push_back(gatewayspk); pubkeys.push_back(gatewayspk);
opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << coin << totalsupply << oracletxid << M << N << gatewaypubkeys << taddr << prefix << prefix2); opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << coin << totalsupply << oracletxid << M << N << gatewaypubkeys << taddr << prefix << prefix2 << wiftype);
return(EncodeTokenOpRet(tokenid,pubkeys,opret)); return(EncodeTokenOpRet(tokenid,pubkeys,opret));
} }
uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,uint256 &tokenid,std::string &coin,int64_t &totalsupply,uint256 &oracletxid,uint8_t &M,uint8_t &N,std::vector<CPubKey> &gatewaypubkeys,uint8_t &taddr,uint8_t &prefix,uint8_t &prefix2) uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,uint256 &tokenid,std::string &coin,int64_t &totalsupply,uint256 &oracletxid,uint8_t &M,uint8_t &N,std::vector<CPubKey> &gatewaypubkeys,uint8_t &taddr,uint8_t &prefix,uint8_t &prefix2,uint8_t wiftype)
{ {
std::vector<uint8_t> vopret; uint8_t *script,e,f,tokenevalcode; std::vector<uint8_t> vopret; uint8_t *script,e,f,tokenevalcode;
std::vector<uint8_t> vOpretExtra; std::vector<CPubKey> pubkeys; std::vector<uint8_t> vOpretExtra; std::vector<CPubKey> pubkeys;
@@ -171,28 +177,30 @@ uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,ui
else GetOpReturnData(scriptPubKey, vopret); else GetOpReturnData(scriptPubKey, vopret);
script = (uint8_t *)vopret.data(); script = (uint8_t *)vopret.data();
depositaddr[0] = 0; depositaddr[0] = 0;
if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> coin; ss >> totalsupply; ss >> oracletxid; ss >> M; ss >> N; ss >> gatewaypubkeys; ss >> taddr; ss >> prefix; ss >> prefix2;) != 0 ) if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> coin; ss >> totalsupply; ss >> oracletxid; ss >> M; ss >> N; ss >> gatewaypubkeys; ss >> taddr; ss >> prefix; ss >> prefix2; ss >> wiftype) != 0 )
{ {
if ( prefix == 60 ) if ( prefix == KMD_PUBTYPE && prefix2 == KMD_P2SHTYPE )
{ {
if ( N > 1 ) if ( N > 1 )
{ {
strcpy(depositaddr,CBitcoinAddress(CScriptID(GetScriptForMultisig(M,gatewaypubkeys))).ToString().c_str()); strcpy(depositaddr,CBitcoinAddress(CScriptID(GetScriptForMultisig(M,gatewaypubkeys))).ToString().c_str());
//LogPrint("gatewayscc","f.%c M.%d of N.%d size.%d -> %s\n",f,M,N,(int32_t)gatewaypubkeys.size(),depositaddr); LogPrint("gatewayscc-1","f.%c M.%d of N.%d size.%d -> %s\n",f,M,N,(int32_t)gatewaypubkeys.size(),depositaddr);
} else Getscriptaddress(depositaddr,CScript() << ParseHex(HexStr(gatewaypubkeys[0])) << OP_CHECKSIG); } else Getscriptaddress(depositaddr,CScript() << ParseHex(HexStr(gatewaypubkeys[0])) << OP_CHECKSIG);
} }
else else
{ {
LogPrint("gatewayscc","need to generate non-KMD addresses prefix.%d\n",prefix); if ( N > 1 ) strcpy(depositaddr,CCustomBitcoinAddress(CScriptID(GetScriptForMultisig(M,gatewaypubkeys)),taddr,prefix,prefix2).ToString().c_str());
else GetCustomscriptaddress(depositaddr,CScript() << ParseHex(HexStr(gatewaypubkeys[0])) << OP_CHECKSIG,taddr,prefix,prefix2);
} }
return(f); return(f);
} else LogPrint("gatewayscc","error decoding bind opret\n"); } else LogPrint("gatewayscc-1","error decoding bind opret\n");
return(0); return(0);
} }
CScript EncodeGatewaysDepositOpRet(uint8_t funcid,uint256 bindtxid,std::string refcoin,std::vector<CPubKey> publishers,std::vector<uint256>txids,int32_t height,uint256 cointxid,int32_t claimvout,std::string deposithex,std::vector<uint8_t>proof,CPubKey destpub,int64_t amount) CScript EncodeGatewaysDepositOpRet(uint8_t funcid,uint256 bindtxid,std::string refcoin,std::vector<CPubKey> publishers,std::vector<uint256>txids,int32_t height,uint256 cointxid,int32_t claimvout,std::string deposithex,std::vector<uint8_t>proof,CPubKey destpub,int64_t amount)
{ {
CScript opret; uint8_t evalcode = EVAL_GATEWAYS; CScript opret; uint8_t evalcode = EVAL_GATEWAYS;
opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << refcoin << bindtxid << publishers << txids << height << cointxid << claimvout << deposithex << proof << destpub << amount); opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << refcoin << bindtxid << publishers << txids << height << cointxid << claimvout << deposithex << proof << destpub << amount);
return(opret); return(opret);
} }
@@ -200,6 +208,7 @@ CScript EncodeGatewaysDepositOpRet(uint8_t funcid,uint256 bindtxid,std::string r
uint8_t DecodeGatewaysDepositOpRet(const CScript &scriptPubKey,uint256 &bindtxid,std::string &refcoin,std::vector<CPubKey>&publishers,std::vector<uint256>&txids,int32_t &height,uint256 &cointxid, int32_t &claimvout,std::string &deposithex,std::vector<uint8_t> &proof,CPubKey &destpub,int64_t &amount) uint8_t DecodeGatewaysDepositOpRet(const CScript &scriptPubKey,uint256 &bindtxid,std::string &refcoin,std::vector<CPubKey>&publishers,std::vector<uint256>&txids,int32_t &height,uint256 &cointxid, int32_t &claimvout,std::string &deposithex,std::vector<uint8_t> &proof,CPubKey &destpub,int64_t &amount)
{ {
std::vector<uint8_t> vopret; uint8_t *script,e,f; std::vector<uint8_t> vopret; uint8_t *script,e,f;
GetOpReturnData(scriptPubKey, vopret); GetOpReturnData(scriptPubKey, vopret);
script = (uint8_t *)vopret.data(); script = (uint8_t *)vopret.data();
if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> refcoin; ss >> bindtxid; ss >> publishers; ss >> txids; ss >> height; ss >> cointxid; ss >> claimvout; ss >> deposithex; ss >> proof; ss >> destpub; ss >> amount) != 0 ) if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> refcoin; ss >> bindtxid; ss >> publishers; ss >> txids; ss >> height; ss >> cointxid; ss >> claimvout; ss >> deposithex; ss >> proof; ss >> destpub; ss >> amount) != 0 )
@@ -270,6 +279,7 @@ uint8_t DecodeGatewaysWithdrawOpRet(const CScript &scriptPubKey, uint256& tokeni
CScript EncodeGatewaysPartialOpRet(uint8_t funcid, uint256 withdrawtxid,std::string refcoin,uint8_t K, CPubKey signerpk,std::string hex) CScript EncodeGatewaysPartialOpRet(uint8_t funcid, uint256 withdrawtxid,std::string refcoin,uint8_t K, CPubKey signerpk,std::string hex)
{ {
CScript opret; uint8_t evalcode = EVAL_GATEWAYS; CScript opret; uint8_t evalcode = EVAL_GATEWAYS;
opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << withdrawtxid << refcoin << K << signerpk << hex); opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << withdrawtxid << refcoin << K << signerpk << hex);
return(opret); return(opret);
} }
@@ -296,6 +306,7 @@ CScript EncodeGatewaysCompleteSigningOpRet(uint8_t funcid,uint256 withdrawtxid,s
uint8_t DecodeGatewaysCompleteSigningOpRet(const CScript &scriptPubKey,uint256 &withdrawtxid,std::string &refcoin,uint8_t &K,std::string &hex) uint8_t DecodeGatewaysCompleteSigningOpRet(const CScript &scriptPubKey,uint256 &withdrawtxid,std::string &refcoin,uint8_t &K,std::string &hex)
{ {
std::vector<uint8_t> vopret; uint8_t *script,e,f; std::vector<uint8_t> vopret; uint8_t *script,e,f;
GetOpReturnData(scriptPubKey, vopret); GetOpReturnData(scriptPubKey, vopret);
script = (uint8_t *)vopret.data(); script = (uint8_t *)vopret.data();
if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> withdrawtxid; ss >> refcoin; ss >> K; ss >> hex) != 0 ) if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> withdrawtxid; ss >> refcoin; ss >> K; ss >> hex) != 0 )
@@ -308,6 +319,7 @@ uint8_t DecodeGatewaysCompleteSigningOpRet(const CScript &scriptPubKey,uint256 &
CScript EncodeGatewaysMarkDoneOpRet(uint8_t funcid,uint256 withdrawtxid,std::string refcoin,uint256 completetxid) CScript EncodeGatewaysMarkDoneOpRet(uint8_t funcid,uint256 withdrawtxid,std::string refcoin,uint256 completetxid)
{ {
CScript opret; uint8_t evalcode = EVAL_GATEWAYS; CScript opret; uint8_t evalcode = EVAL_GATEWAYS;
opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << withdrawtxid << refcoin << completetxid); opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << withdrawtxid << refcoin << completetxid);
return(opret); return(opret);
} }
@@ -315,6 +327,7 @@ CScript EncodeGatewaysMarkDoneOpRet(uint8_t funcid,uint256 withdrawtxid,std::str
uint8_t DecodeGatewaysMarkDoneOpRet(const CScript &scriptPubKey, uint256 &withdrawtxid, std::string &refcoin, uint256 &completetxid) uint8_t DecodeGatewaysMarkDoneOpRet(const CScript &scriptPubKey, uint256 &withdrawtxid, std::string &refcoin, uint256 &completetxid)
{ {
std::vector<uint8_t> vopret; uint8_t *script,e,f; std::vector<uint8_t> vopret; uint8_t *script,e,f;
GetOpReturnData(scriptPubKey, vopret); GetOpReturnData(scriptPubKey, vopret);
script = (uint8_t *)vopret.data(); script = (uint8_t *)vopret.data();
if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> withdrawtxid; ss >> refcoin; ss >> completetxid;) != 0 ) if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> withdrawtxid; ss >> refcoin; ss >> completetxid;) != 0 )
@@ -347,6 +360,7 @@ uint8_t DecodeGatewaysOpRet(const CScript &scriptPubKey)
int64_t IsGatewaysvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) int64_t IsGatewaysvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v)
{ {
char destaddr[64]; char destaddr[64];
if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) 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,cp->unspendableCCaddr) == 0 )
@@ -359,6 +373,7 @@ bool GatewaysExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti
{ {
static uint256 zerohash; static uint256 zerohash;
CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis;
numvins = tx.vin.size(); numvins = tx.vin.size();
numvouts = tx.vout.size(); numvouts = tx.vout.size();
for (i=0; i<numvins; i++) for (i=0; i<numvins; i++)
@@ -407,7 +422,7 @@ static int32_t myIs_coinaddr_inmempoolvout(char *coinaddr)
Getscriptaddress(destaddr,tx.vout[i].scriptPubKey); Getscriptaddress(destaddr,tx.vout[i].scriptPubKey);
if ( strcmp(destaddr,coinaddr) == 0 ) if ( strcmp(destaddr,coinaddr) == 0 )
{ {
LogPrint("gatewayscc","found (%s) vout in mempool\n",coinaddr); LogPrint("gatewayscc-1","found (%s) vout in mempool\n",coinaddr);
return(1); return(1);
} }
} }
@@ -421,13 +436,13 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u
CTransaction tx; uint256 hash,mhash,bhash,hashBlock,oracletxid; int32_t len,len2,numvouts; int64_t val,merkleht; CPubKey pk; std::vector<uint8_t>data; CTransaction tx; uint256 hash,mhash,bhash,hashBlock,oracletxid; int32_t len,len2,numvouts; int64_t val,merkleht; CPubKey pk; std::vector<uint8_t>data;
txid = zeroid; txid = zeroid;
char str[65]; char str[65];
//LogPrint("gatewayscc","start reverse scan %s\n",uint256_str(str,batontxid)); LogPrint("gatewayscc-2","start reverse scan %s\n",uint256_str(str,batontxid));
while ( myGetTransaction(batontxid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 ) while ( myGetTransaction(batontxid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 )
{ {
//LogPrint("gatewayscc","check %s\n",uint256_str(str,batontxid)); LogPrint("gatewayscc-2","check %s\n",uint256_str(str,batontxid));
if ( DecodeOraclesData(tx.vout[numvouts-1].scriptPubKey,oracletxid,bhash,pk,data) == 'D' && oracletxid == reforacletxid ) if ( DecodeOraclesData(tx.vout[numvouts-1].scriptPubKey,oracletxid,bhash,pk,data) == 'D' && oracletxid == reforacletxid )
{ {
//LogPrint("gatewayscc","decoded %s\n",uint256_str(str,batontxid)); LogPrint("gatewayscc-2","decoded %s\n",uint256_str(str,batontxid));
if ( oracle_format(&hash,&merkleht,0,'I',(uint8_t *)data.data(),0,(int32_t)data.size()) == sizeof(int32_t) && merkleht == height ) if ( oracle_format(&hash,&merkleht,0,'I',(uint8_t *)data.data(),0,(int32_t)data.size()) == sizeof(int32_t) && merkleht == height )
{ {
len = oracle_format(&hash,&val,0,'h',(uint8_t *)data.data(),sizeof(int32_t),(int32_t)data.size()); len = oracle_format(&hash,&val,0,'h',(uint8_t *)data.data(),sizeof(int32_t),(int32_t)data.size());
@@ -436,20 +451,20 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u
if ( len == sizeof(hash)+sizeof(int32_t) && len2 == 2*sizeof(mhash)+sizeof(int32_t) && mhash != zeroid ) if ( len == sizeof(hash)+sizeof(int32_t) && len2 == 2*sizeof(mhash)+sizeof(int32_t) && mhash != zeroid )
{ {
txid = batontxid; txid = batontxid;
//LogPrint("gatewayscc","set txid\n"); LogPrint("gatewayscc-2","set txid\n");
return(mhash); return(mhash);
} }
else else
{ {
//LogPrint("gatewayscc","missing hash\n"); LogPrint("gatewayscc-2","missing hash\n");
return(zeroid); return(zeroid);
} }
} //else LogPrint("gatewayscc","height.%d vs search ht.%d\n",(int32_t)merkleht,(int32_t)height); } else LogPrint("gatewayscc-2","height.%d vs search ht.%d\n",(int32_t)merkleht,(int32_t)height);
batontxid = bhash; batontxid = bhash;
//LogPrint("gatewayscc","new hash %s\n",uint256_str(str,batontxid)); LogPrint("gatewayscc-2","new hash %s\n",uint256_str(str,batontxid));
} else break; } else break;
} }
LogPrint("gatewayscc","end of loop\n"); LogPrint("gatewayscc-2","end of loop\n");
return(zeroid); return(zeroid);
} }
@@ -479,7 +494,7 @@ uint256 BitcoinGetProofMerkleRoot(const std::vector<uint8_t> &proofData, std::ve
return merkleBlock.txn.ExtractMatches(txids); return merkleBlock.txn.ExtractMatches(txids);
} }
int64_t GatewaysVerify(char *refdepositaddr,uint256 oracletxid,int32_t claimvout,std::string refcoin,uint256 cointxid,const std::string deposithex,std::vector<uint8_t>proof,uint256 merkleroot,CPubKey destpub) int64_t GatewaysVerify(char *refdepositaddr,uint256 oracletxid,int32_t claimvout,std::string refcoin,uint256 cointxid,const std::string deposithex,std::vector<uint8_t>proof,uint256 merkleroot,CPubKey destpub,uint8_t taddr,uint8_t prefix,uint8_t prefix2)
{ {
std::vector<uint256> txids; uint256 proofroot,hashBlock,txid = zeroid; CTransaction tx; std::string name,description,format; std::vector<uint256> txids; uint256 proofroot,hashBlock,txid = zeroid; CTransaction tx; std::string name,description,format;
char destaddr[64],destpubaddr[64],claimaddr[64],str[65],str2[65]; int32_t i,numvouts; int64_t nValue = 0; char destaddr[64],destpubaddr[64],claimaddr[64],str[65],str2[65]; int32_t i,numvouts; int64_t nValue = 0;
@@ -507,13 +522,13 @@ int64_t GatewaysVerify(char *refdepositaddr,uint256 oracletxid,int32_t claimvout
} }
if ( DecodeHexTx(tx,deposithex) != 0 ) if ( DecodeHexTx(tx,deposithex) != 0 )
{ {
Getscriptaddress(claimaddr,tx.vout[claimvout].scriptPubKey); GetCustomscriptaddress(claimaddr,tx.vout[claimvout].scriptPubKey,taddr,prefix,prefix2);
Getscriptaddress(destpubaddr,CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG); GetCustomscriptaddress(destpubaddr,CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG,taddr,prefix,prefix2);
if ( strcmp(claimaddr,destpubaddr) == 0 ) if ( strcmp(claimaddr,destpubaddr) == 0 )
{ {
for (i=0; i<numvouts; i++) for (i=0; i<numvouts; i++)
{ {
Getscriptaddress(destaddr,tx.vout[i].scriptPubKey); GetCustomscriptaddress(destaddr,tx.vout[i].scriptPubKey,taddr,prefix,prefix2);
if ( strcmp(refdepositaddr,destaddr) == 0 ) if ( strcmp(refdepositaddr,destaddr) == 0 )
{ {
txid = tx.GetHash(); txid = tx.GetHash();
@@ -521,13 +536,13 @@ int64_t GatewaysVerify(char *refdepositaddr,uint256 oracletxid,int32_t claimvout
break; break;
} }
} }
if ( txid == cointxid )
{
LogPrint("gatewayscc-1","verified proof for cointxid in merkleroot\n");
return(nValue);
} else LogPrint("gatewayscc","(%s) != (%s) or txid %s mismatch.%d or script mismatch\n",refdepositaddr,destaddr,uint256_str(str,txid),txid != cointxid);
} else LogPrint("gatewayscc","claimaddr.(%s) != destpubaddr.(%s)\n",claimaddr,destpubaddr); } else LogPrint("gatewayscc","claimaddr.(%s) != destpubaddr.(%s)\n",claimaddr,destpubaddr);
} }
if ( txid == cointxid )
{
LogPrint("gatewayscc","verified proof for cointxid in merkleroot\n");
return(nValue);
} else LogPrint("gatewayscc","(%s) != (%s) or txid %s mismatch.%d or script mismatch\n",refdepositaddr,destaddr,uint256_str(str,txid),txid != cointxid);
return(0); return(0);
} }
@@ -538,8 +553,6 @@ int64_t GatewaysDepositval(CTransaction tx,CPubKey mypk)
{ {
if ( DecodeGatewaysDepositOpRet(tx.vout[numvouts-1].scriptPubKey,bindtxid,coin,publishers,txids,height,cointxid,claimvout,deposithex,proof,claimpubkey,amount) == 'D' && claimpubkey == mypk ) if ( DecodeGatewaysDepositOpRet(tx.vout[numvouts-1].scriptPubKey,bindtxid,coin,publishers,txids,height,cointxid,claimvout,deposithex,proof,claimpubkey,amount) == 'D' && claimpubkey == mypk )
{ {
// coin, bindtxid, publishers
//LogPrint("gatewayscc","need to validate deposittxid more\n");
return(amount); return(amount);
} }
} }
@@ -549,7 +562,7 @@ int64_t GatewaysDepositval(CTransaction tx,CPubKey mypk)
int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 reftokenid) int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 reftokenid)
{ {
char markeraddr[64],depositaddr[64]; std::string coin; int32_t numvouts; int64_t totalsupply; uint256 tokenid,oracletxid,hashBlock; char markeraddr[64],depositaddr[64]; std::string coin; int32_t numvouts; int64_t totalsupply; uint256 tokenid,oracletxid,hashBlock;
uint8_t M,N,taddr,prefix,prefix2; std::vector<CPubKey> pubkeys; CTransaction tx; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> pubkeys; CTransaction tx;
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex; std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
_GetCCaddress(markeraddr,EVAL_GATEWAYS,gatewayspk); _GetCCaddress(markeraddr,EVAL_GATEWAYS,gatewayspk);
@@ -558,7 +571,7 @@ int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256
{ {
if ( myGetTransaction(it->first.txhash,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 && DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey)=='B' ) if ( myGetTransaction(it->first.txhash,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 && DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey)=='B' )
{ {
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) == 'B' ) if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) == 'B' )
{ {
if ( tokenid == reftokenid ) if ( tokenid == reftokenid )
{ {
@@ -574,7 +587,7 @@ int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256
const uint256 &hash = txmempool.GetHash(); const uint256 &hash = txmempool.GetHash();
if ((numvouts=txmempool.vout.size()) > 0 && DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey)=='B') if ((numvouts=txmempool.vout.size()) > 0 && DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey)=='B')
if (DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) == 'B' && if (DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) == 'B' &&
tokenid == reftokenid) tokenid == reftokenid)
return(1); return(1);
} }
@@ -584,7 +597,7 @@ int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256
bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn)
{ {
int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks,height,claimvout; bool retval; uint8_t funcid,hash[32],K,M,N,taddr,prefix,prefix2; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks,height,claimvout; bool retval; uint8_t funcid,hash[32],K,M,N,taddr,prefix,prefix2,wiftype;
char str[65],destaddr[64],depositaddr[65],validationError[512]; char str[65],destaddr[64],depositaddr[65],validationError[512];
std::vector<uint256> txids; std::vector<CPubKey> pubkeys,publishers,tmppublishers; std::vector<uint8_t> proof; int64_t fullsupply,totalsupply,amount,tmpamount; std::vector<uint256> txids; std::vector<CPubKey> pubkeys,publishers,tmppublishers; std::vector<uint8_t> proof; int64_t fullsupply,totalsupply,amount,tmpamount;
uint256 hashblock,txid,bindtxid,deposittxid,withdrawtxid,completetxid,tokenid,tmptokenid,oracletxid,bindtokenid,cointxid,tmptxid,merkleroot,mhash; CTransaction bindtx,tmptx; uint256 hashblock,txid,bindtxid,deposittxid,withdrawtxid,completetxid,tokenid,tmptokenid,oracletxid,bindtokenid,cointxid,tmptxid,merkleroot,mhash; CTransaction bindtx,tmptx;
@@ -597,11 +610,10 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
return eval->Invalid("no vouts"); return eval->Invalid("no vouts");
else else
{ {
//LogPrint("gatewayscc","check amounts\n"); //LogPrint("gatewayscc-1","check amounts\n");
// if ( GatewaysExactAmounts(cp,eval,tx,1,10000) == false ) // if ( GatewaysExactAmounts(cp,eval,tx,1,10000) == false )
// { // {
// LogPrint("gatewayscc","Gatewaysget invalid amount\n"); // return eval->Invalid("invalid inputs vs. outputs!");
// return false;
// } // }
// else // else
// { // {
@@ -615,7 +627,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
//vin.1: CC input of tokens //vin.1: CC input of tokens
//vout.0: CC vout of gateways tokens to gateways tokens CC address //vout.0: CC vout of gateways tokens to gateways tokens CC address
//vout.1: CC vout txfee marker //vout.1: CC vout txfee marker
//vout.n-1: opreturn - 'B' tokenid coin totalsupply oracletxid M N pubkeys taddr prefix prefix2 //vout.n-1: opreturn - 'B' tokenid coin totalsupply oracletxid M N pubkeys taddr prefix prefix2 wiftype
return eval->Invalid("unexpected GatewaysValidate for gatewaysbind!"); return eval->Invalid("unexpected GatewaysValidate for gatewaysbind!");
break; break;
case 'D': case 'D':
@@ -644,7 +656,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
return eval->Invalid("vout.0 is CC for gatewaysClaim!"); return eval->Invalid("vout.0 is CC for gatewaysClaim!");
else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0)
return eval->Invalid("invalid gatewaysbind txid!"); return eval->Invalid("invalid gatewaysbind txid!");
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B') else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B')
return eval->Invalid("invalid gatewaysbind OP_RETURN data!"); return eval->Invalid("invalid gatewaysbind OP_RETURN data!");
else if (tmprefcoin!=refcoin) else if (tmprefcoin!=refcoin)
return eval->Invalid("refcoin different than in bind tx"); return eval->Invalid("refcoin different than in bind tx");
@@ -718,7 +730,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
sprintf(validationError,"couldnt find merkleroot for ht.%d %s oracle.%s m.%d vs n.%d\n",height,tmprefcoin.c_str(),uint256_str(str,oracletxid),m,N); sprintf(validationError,"couldnt find merkleroot for ht.%d %s oracle.%s m.%d vs n.%d\n",height,tmprefcoin.c_str(),uint256_str(str,oracletxid),m,N);
return eval->Invalid(validationError); return eval->Invalid(validationError);
} }
else if (GatewaysVerify(depositaddr,oracletxid,claimvout,tmprefcoin,cointxid,hex,proof,merkleroot,pubkey)!=amount) else if (GatewaysVerify(depositaddr,oracletxid,claimvout,tmprefcoin,cointxid,hex,proof,merkleroot,pubkey,taddr,prefix,prefix2)!=amount)
return eval->Invalid("external deposit not verified\n"); return eval->Invalid("external deposit not verified\n");
} }
break; break;
@@ -764,7 +776,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!");
else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0)
return eval->Invalid("invalid gatewaysbind txid!"); return eval->Invalid("invalid gatewaysbind txid!");
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B') else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B')
return eval->Invalid("invalid gatewaysbind OP_RETURN data!"); return eval->Invalid("invalid gatewaysbind OP_RETURN data!");
else if (tmprefcoin!=refcoin) else if (tmprefcoin!=refcoin)
return eval->Invalid("refcoin different than in bind tx"); return eval->Invalid("refcoin different than in bind tx");
@@ -808,7 +820,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!");
else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0)
return eval->Invalid("invalid gatewaysbind txid!"); return eval->Invalid("invalid gatewaysbind txid!");
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B') else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B')
return eval->Invalid("invalid gatewaysbind OP_RETURN data!"); return eval->Invalid("invalid gatewaysbind OP_RETURN data!");
else if (tmprefcoin!=refcoin) else if (tmprefcoin!=refcoin)
return eval->Invalid("refcoin different than in bind tx"); return eval->Invalid("refcoin different than in bind tx");
@@ -846,7 +858,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!");
else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0)
return eval->Invalid("invalid gatewaysbind txid!"); return eval->Invalid("invalid gatewaysbind txid!");
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B') else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B')
return eval->Invalid("invalid gatewaysbind OP_RETURN data!"); return eval->Invalid("invalid gatewaysbind OP_RETURN data!");
else if (tmprefcoin!=refcoin) else if (tmprefcoin!=refcoin)
return eval->Invalid("refcoin different than in bind tx"); return eval->Invalid("refcoin different than in bind tx");
@@ -861,7 +873,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
} }
retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts);
if ( retval != 0 ) if ( retval != 0 )
fprintf(stderr,"Gateways tx validated\n"); LogPrint("gatewayscc","Gateways tx validated\n");
else fprintf(stderr,"Gateways tx invalid\n"); else fprintf(stderr,"Gateways tx invalid\n");
return(retval); return(retval);
// } // }
@@ -874,29 +886,22 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 bindtxid,int64_t total,int32_t maxinputs) int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 bindtxid,int64_t total,int32_t maxinputs)
{ {
char coinaddr[64],depositaddr[64]; int64_t threshold,nValue,price,totalinputs = 0,totalsupply,amount; char coinaddr[64],depositaddr[64]; int64_t threshold,nValue,price,totalinputs = 0,totalsupply,amount;
CTransaction vintx,bindtx; int32_t vout,numvouts,n = 0; uint8_t M,N,evalcode,funcid,taddr,prefix,prefix2; std::vector<CPubKey> pubkeys; CTransaction vintx,bindtx; int32_t vout,numvouts,n = 0; uint8_t M,N,evalcode,funcid,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> pubkeys;
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; std::string refcoin,tmprefcoin; CPubKey withdrawpub,destpub; std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; std::string refcoin,tmprefcoin; CPubKey withdrawpub,destpub;
uint256 tokenid,txid,oracletxid,tmpbindtxid,tmptokenid,deposittxid,hashBlock; uint256 tokenid,txid,oracletxid,tmpbindtxid,tmptokenid,deposittxid,hashBlock;
if ( GetTransaction(bindtxid,bindtx,hashBlock,false) != 0 ) if ( GetTransaction(bindtxid,bindtx,hashBlock,false) != 0 )
{ {
if ((numvouts=bindtx.vout.size())!=0 && DecodeGatewaysBindOpRet(depositaddr,bindtx.vout[numvouts-1].scriptPubKey,tokenid,refcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) == 'B') if ((numvouts=bindtx.vout.size())!=0 && DecodeGatewaysBindOpRet(depositaddr,bindtx.vout[numvouts-1].scriptPubKey,tokenid,refcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) == 'B')
{ {
GetTokensCCaddress(cp,coinaddr,pk); GetTokensCCaddress(cp,coinaddr,pk);
SetCCunspents(unspentOutputs,coinaddr); SetCCunspents(unspentOutputs,coinaddr);
threshold = total/(maxinputs+1); threshold = total/(maxinputs+1);
LogPrint("gatewayscc","check %s for gateway inputs\n",coinaddr); LogPrint("gatewayscc-1","check %s for gateway inputs\n",coinaddr);
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
{ {
txid = it->first.txhash; txid = it->first.txhash;
vout = (int32_t)it->first.index; 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;
// if ( j != mtx.vin.size() )
// continue;
if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) if ( GetTransaction(txid,vintx,hashBlock,false) != 0 )
{ {
funcid=DecodeGatewaysOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey); funcid=DecodeGatewaysOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey);
@@ -933,10 +938,10 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP
return(0); return(0);
} }
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 GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector<CPubKey> pubkeys,uint8_t p1,uint8_t p2,uint8_t p3,uint8_t p4)
{ {
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
CTransaction oracletx; uint8_t taddr,prefix,prefix2; CPubKey mypk,gatewayspk; CScript opret; uint256 hashBlock; CTransaction oracletx; uint8_t taddr,prefix,prefix2,wiftype; CPubKey mypk,gatewayspk; CScript opret; uint256 hashBlock;
struct CCcontract_info *cp,*cpTokens,C,CTokens; std::string name,description,format; int32_t i,numvouts; int64_t fullsupply; struct CCcontract_info *cp,*cpTokens,C,CTokens; std::string name,description,format; int32_t i,numvouts; int64_t fullsupply;
char destaddr[64],coinaddr[64],myTokenCCaddr[64],str[65],*fstr; char destaddr[64],coinaddr[64],myTokenCCaddr[64],str[65],*fstr;
@@ -944,16 +949,18 @@ std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t
cpTokens = CCinit(&CTokens,EVAL_TOKENS); cpTokens = CCinit(&CTokens,EVAL_TOKENS);
if (coin=="KMD") if (coin=="KMD")
{ {
taddr = 0; prefix = KMD_PUBTYPE;
prefix = 60; prefix2 = KMD_P2SHTYPE;
prefix2 = 85; wiftype = KMD_WIFTYPE;
taddr = KMD_TADDR;
} }
else else
{ {
LogPrint("gatewayscc","set taddr, prefix, prefix2 for %s\n",coin.c_str()); prefix = p1;
taddr = 0; prefix2 = p2;
prefix = 60; wiftype = p3;
prefix2 = 85; taddr = p4;
LogPrint("gatewayscc-1","set prefix %d, prefix2 %d, wiftype %d for %s\n",prefix,prefix2,wiftype,coin.c_str());
} }
if ( N == 0 || N > 15 || M > N ) if ( N == 0 || N > 15 || M > N )
{ {
@@ -1030,7 +1037,7 @@ std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t
{ {
mtx.vout.push_back(MakeTokensCC1vout(cp->evalcode,totalsupply,gatewayspk)); mtx.vout.push_back(MakeTokensCC1vout(cp->evalcode,totalsupply,gatewayspk));
mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,gatewayspk)); mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,gatewayspk));
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeGatewaysBindOpRet('B',tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2))); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeGatewaysBindOpRet('B',tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype)));
} }
} }
CCerror = strprintf("cant find enough inputs"); CCerror = strprintf("cant find enough inputs");
@@ -1042,23 +1049,23 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std::
{ {
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
CTransaction bindtx; CPubKey mypk; uint256 oracletxid,merkleroot,mhash,hashBlock,tokenid,txid; CTransaction bindtx; CPubKey mypk; uint256 oracletxid,merkleroot,mhash,hashBlock,tokenid,txid;
int64_t totalsupply; int32_t i,m,n,numvouts; uint8_t M,N,taddr,prefix,prefix2; std::string coin; struct CCcontract_info *cp,C; int64_t totalsupply; int32_t i,m,n,numvouts; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::string coin; struct CCcontract_info *cp,C;
std::vector<CPubKey> pubkeys,publishers; std::vector<uint256>txids; char str[67],depositaddr[64],txidaddr[64]; std::vector<CPubKey> pubkeys,publishers; std::vector<uint256>txids; char str[67],depositaddr[64],txidaddr[64];
cp = CCinit(&C,EVAL_GATEWAYS); cp = CCinit(&C,EVAL_GATEWAYS);
if ( txfee == 0 ) if ( txfee == 0 )
txfee = 10000; txfee = 10000;
mypk = pubkey2pk(Mypubkey()); mypk = pubkey2pk(Mypubkey());
//LogPrint("gatewayscc","GatewaysDeposit ht.%d %s %.8f numpks.%d\n",height,refcoin.c_str(),(double)amount/COIN,(int32_t)pubkeys.size()); LogPrint("gatewayscc-1","GatewaysDeposit ht.%d %s %.8f numpks.%d\n",height,refcoin.c_str(),(double)amount/COIN,(int32_t)pubkeys.size());
if ( GetTransaction(bindtxid,bindtx,hashBlock,false) == 0 || (numvouts= bindtx.vout.size()) <= 0 ) if ( GetTransaction(bindtxid,bindtx,hashBlock,false) == 0 || (numvouts= bindtx.vout.size()) <= 0 )
{ {
CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)); CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid));
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return(""); return("");
} }
if ( DecodeGatewaysBindOpRet(depositaddr,bindtx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B' || refcoin != coin ) if ( DecodeGatewaysBindOpRet(depositaddr,bindtx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B' || refcoin != coin )
{ {
CCerror = strprintf("invalid coin - bindtxid %s coin.%n",uint256_str(str,bindtxid),coin.c_str()); CCerror = strprintf("invalid coin - bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str());
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return(""); return("");
} }
@@ -1086,9 +1093,6 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std::
LogPrint("gatewayscc","cointxid.%s m.%d of n.%d\n",uint256_str(str,cointxid),m,n); LogPrint("gatewayscc","cointxid.%s m.%d of n.%d\n",uint256_str(str,cointxid),m,n);
if ( merkleroot == zeroid || m < n/2 ) if ( merkleroot == zeroid || m < n/2 )
{ {
//uint256 tmp;
//decode_hex((uint8_t *)&tmp,32,(char *)"90aedc2f19200afc9aca2e351438d011ebae8264a58469bf225883045f61917f");
//merkleroot = revuint256(tmp);
CCerror = strprintf("couldnt find merkleroot for ht.%d %s oracle.%s m.%d vs n.%d",height,coin.c_str(),uint256_str(str,oracletxid),m,n); CCerror = strprintf("couldnt find merkleroot for ht.%d %s oracle.%s m.%d vs n.%d",height,coin.c_str(),uint256_str(str,oracletxid),m,n);
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return(""); return("");
@@ -1099,7 +1103,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std::
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return(""); return("");
} }
if ( GatewaysVerify(depositaddr,oracletxid,claimvout,coin,cointxid,deposithex,proof,merkleroot,destpub) != amount ) if ( GatewaysVerify(depositaddr,oracletxid,claimvout,coin,cointxid,deposithex,proof,merkleroot,destpub,taddr,prefix,prefix2) != amount )
{ {
CCerror = strprintf("deposittxid didnt validate"); CCerror = strprintf("deposittxid didnt validate");
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
@@ -1119,7 +1123,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) std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount)
{ {
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
CTransaction tx; CPubKey mypk,gatewayspk,tmpdestpub; struct CCcontract_info *cp,C; uint8_t M,N,taddr,prefix,prefix2; CTransaction tx; CPubKey mypk,gatewayspk,tmpdestpub; struct CCcontract_info *cp,C; uint8_t M,N,taddr,prefix,prefix2,wiftype;
std::string coin, deposithex; std::vector<CPubKey> msigpubkeys,publishers; int64_t totalsupply,depositamount,tmpamount,inputs,CCchange=0; std::string coin, deposithex; std::vector<CPubKey> msigpubkeys,publishers; int64_t totalsupply,depositamount,tmpamount,inputs,CCchange=0;
int32_t numvouts,claimvout,height; std::vector<uint8_t> proof; int32_t numvouts,claimvout,height; std::vector<uint8_t> proof;
uint256 hashBlock,tokenid,oracletxid,tmptxid,cointxid; char str[65],depositaddr[64],coinaddr[64],destaddr[64]; std::vector<uint256> txids; uint256 hashBlock,tokenid,oracletxid,tmptxid,cointxid; char str[65],depositaddr[64],coinaddr[64],destaddr[64]; std::vector<uint256> txids;
@@ -1135,7 +1139,7 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return(""); return("");
} }
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B' || coin != refcoin ) if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2,wiftype) != 'B' || coin != refcoin )
{ {
CCerror = strprintf("invalid coin - bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str()); CCerror = strprintf("invalid coin - bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str());
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
@@ -1197,7 +1201,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin
{ {
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
CTransaction tx; CPubKey mypk,gatewayspk,signerpk; uint256 txid,tokenid,hashBlock,oracletxid,tmptokenid,tmpbindtxid,withdrawtxid; int32_t vout,numvouts; CTransaction tx; CPubKey mypk,gatewayspk,signerpk; uint256 txid,tokenid,hashBlock,oracletxid,tmptokenid,tmpbindtxid,withdrawtxid; int32_t vout,numvouts;
int64_t nValue,totalsupply,inputs,CCchange=0,tmpamount; uint8_t funcid,K,M,N,taddr,prefix,prefix2; std::string coin,hex; int64_t nValue,totalsupply,inputs,CCchange=0,tmpamount; uint8_t funcid,K,M,N,taddr,prefix,prefix2,wiftype; std::string coin,hex;
std::vector<CPubKey> msigpubkeys; char depositaddr[64],str[65],coinaddr[64]; struct CCcontract_info *cp,C,*cpTokens,CTokens; std::vector<CPubKey> msigpubkeys; char depositaddr[64],str[65],coinaddr[64]; struct CCcontract_info *cp,C,*cpTokens,CTokens;
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
@@ -1214,7 +1218,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return(""); return("");
} }
if( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B' || coin != refcoin ) if( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2,wiftype) != 'B' || coin != refcoin )
{ {
CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str()); CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str());
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
@@ -1283,7 +1287,7 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 lasttxid,std::string refc
CPubKey mypk,withdrawpub,signerpk,gatewayspk; struct CCcontract_info *cp,C; CTransaction tx,tmptx; CPubKey mypk,withdrawpub,signerpk,gatewayspk; struct CCcontract_info *cp,C; CTransaction tx,tmptx;
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; char funcid,str[65],depositaddr[64]; std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; char funcid,str[65],depositaddr[64];
int32_t numvouts; uint256 withdrawtxid,hashBlock,bindtxid,tokenid,oracletxid,tmptokenid; std::string coin,tmphex; int64_t amount,totalsupply; int32_t numvouts; uint256 withdrawtxid,hashBlock,bindtxid,tokenid,oracletxid,tmptokenid; std::string coin,tmphex; int64_t amount,totalsupply;
uint8_t K=0,M,N,taddr,prefix,prefix2; std::vector<CPubKey> pubkeys; uint8_t K=0,M,N,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> pubkeys;
cp = CCinit(&C,EVAL_GATEWAYS); cp = CCinit(&C,EVAL_GATEWAYS);
if ( txfee == 0 ) if ( txfee == 0 )
@@ -1318,7 +1322,7 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 lasttxid,std::string refc
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return(""); return("");
} }
else if (DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B' else if (DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B'
|| refcoin!=coin || tokenid!=tmptokenid) || refcoin!=coin || tokenid!=tmptokenid)
{ {
CCerror = strprintf("invalid bind tx %s",uint256_str(str,bindtxid)); CCerror = strprintf("invalid bind tx %s",uint256_str(str,bindtxid));
@@ -1359,7 +1363,7 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 lasttxid,std::string refc
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return(""); return("");
} }
else if (DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B' else if (DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B'
|| refcoin!=coin || tokenid!=tmptokenid) || refcoin!=coin || tokenid!=tmptokenid)
{ {
CCerror = strprintf("invalid bind tx %s",uint256_str(str,bindtxid)); CCerror = strprintf("invalid bind tx %s",uint256_str(str,bindtxid));
@@ -1383,7 +1387,7 @@ std::string GatewaysCompleteSigning(uint64_t txfee,uint256 lasttxid,std::string
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
CPubKey mypk,gatewayspk,signerpk,withdrawpub; struct CCcontract_info *cp,C; char funcid,str[65],depositaddr[64]; int64_t amount,totalsupply; CPubKey mypk,gatewayspk,signerpk,withdrawpub; struct CCcontract_info *cp,C; char funcid,str[65],depositaddr[64]; int64_t amount,totalsupply;
std::string coin,tmphex; CTransaction tx,tmptx; uint256 withdrawtxid,hashBlock,tokenid,tmptokenid,bindtxid,oracletxid; int32_t numvouts; std::string coin,tmphex; CTransaction tx,tmptx; uint256 withdrawtxid,hashBlock,tokenid,tmptokenid,bindtxid,oracletxid; int32_t numvouts;
uint8_t K=0,M,N,taddr,prefix,prefix2; std::vector<CPubKey> pubkeys; uint8_t K=0,M,N,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> pubkeys;
cp = CCinit(&C,EVAL_GATEWAYS); cp = CCinit(&C,EVAL_GATEWAYS);
mypk = pubkey2pk(Mypubkey()); mypk = pubkey2pk(Mypubkey());
@@ -1418,7 +1422,7 @@ std::string GatewaysCompleteSigning(uint64_t txfee,uint256 lasttxid,std::string
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return(""); return("");
} }
else if (DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B' else if (DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B'
|| refcoin!=coin || tokenid!=tmptokenid) || refcoin!=coin || tokenid!=tmptokenid)
{ {
CCerror = strprintf("invalid bind tx %s",uint256_str(str,bindtxid)); CCerror = strprintf("invalid bind tx %s",uint256_str(str,bindtxid));
@@ -1458,7 +1462,7 @@ std::string GatewaysCompleteSigning(uint64_t txfee,uint256 lasttxid,std::string
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return(""); return("");
} }
else if (DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B' else if (DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B'
|| refcoin!=coin || tokenid!=tmptokenid) || refcoin!=coin || tokenid!=tmptokenid)
{ {
CCerror = strprintf("invalid bind tx %s",uint256_str(str,bindtxid)); CCerror = strprintf("invalid bind tx %s",uint256_str(str,bindtxid));
@@ -1482,7 +1486,7 @@ std::string GatewaysMarkDone(uint64_t txfee,uint256 completetxid,std::string ref
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
CPubKey mypk; struct CCcontract_info *cp,C; char str[65],depositaddr[64]; CTransaction tx; int32_t numvouts; CPubKey mypk; struct CCcontract_info *cp,C; char str[65],depositaddr[64]; CTransaction tx; int32_t numvouts;
uint256 withdrawtxid,bindtxid,oracletxid,tokenid,tmptokenid,hashBlock; std::string coin,hex; uint256 withdrawtxid,bindtxid,oracletxid,tokenid,tmptokenid,hashBlock; std::string coin,hex;
uint8_t K,M,N,taddr,prefix,prefix2; std::vector<CPubKey> pubkeys; int64_t amount,totalsupply; CPubKey withdrawpub; uint8_t K,M,N,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> pubkeys; int64_t amount,totalsupply; CPubKey withdrawpub;
cp = CCinit(&C,EVAL_GATEWAYS); cp = CCinit(&C,EVAL_GATEWAYS);
mypk = pubkey2pk(Mypubkey()); mypk = pubkey2pk(Mypubkey());
@@ -1524,7 +1528,7 @@ std::string GatewaysMarkDone(uint64_t txfee,uint256 completetxid,std::string ref
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return(""); return("");
} }
else if (DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B' else if (DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B'
|| refcoin!=coin || tokenid!=tmptokenid) || refcoin!=coin || tokenid!=tmptokenid)
{ {
CCerror = strprintf("invalid bind tx %s",uint256_str(str,bindtxid)); CCerror = strprintf("invalid bind tx %s",uint256_str(str,bindtxid));
@@ -1546,7 +1550,7 @@ UniValue GatewaysPendingDeposits(uint256 bindtxid,std::string refcoin)
{ {
UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string coin,hex,pub; UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string coin,hex,pub;
CPubKey mypk,gatewayspk,destpub; std::vector<CPubKey> pubkeys,publishers; std::vector<uint256> txids; CPubKey mypk,gatewayspk,destpub; std::vector<CPubKey> pubkeys,publishers; std::vector<uint256> txids;
uint256 tmpbindtxid,hashBlock,txid,tokenid,oracletxid,cointxid; uint8_t M,N,taddr,prefix,prefix2; uint256 tmpbindtxid,hashBlock,txid,tokenid,oracletxid,cointxid; uint8_t M,N,taddr,prefix,prefix2,wiftype;
char depositaddr[65],coinaddr[65],str[65],destaddr[65],txidaddr[65]; std::vector<uint8_t> proof; char depositaddr[65],coinaddr[65],str[65],destaddr[65],txidaddr[65]; std::vector<uint8_t> proof;
int32_t numvouts,vout,claimvout,height; int64_t totalsupply,nValue,amount; struct CCcontract_info *cp,C; int32_t numvouts,vout,claimvout,height; int64_t totalsupply,nValue,amount; struct CCcontract_info *cp,C;
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
@@ -1561,7 +1565,7 @@ UniValue GatewaysPendingDeposits(uint256 bindtxid,std::string refcoin)
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return(""); return("");
} }
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B' || refcoin != coin) if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B' || refcoin != coin)
{ {
CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str()); CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str());
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
@@ -1583,6 +1587,7 @@ UniValue GatewaysPendingDeposits(uint256 bindtxid,std::string refcoin)
CCtxidaddr(txidaddr,txid); CCtxidaddr(txidaddr,txid);
obj.push_back(Pair("deposittxidaddr",txidaddr)); obj.push_back(Pair("deposittxidaddr",txidaddr));
_GetCCaddress(destaddr,EVAL_TOKENS,destpub); _GetCCaddress(destaddr,EVAL_TOKENS,destpub);
obj.push_back(Pair("depositaddr",depositaddr));
obj.push_back(Pair("tokens_destination_address",destaddr)); obj.push_back(Pair("tokens_destination_address",destaddr));
pub=HexStr(destpub); pub=HexStr(destpub);
obj.push_back(Pair("claim_pubkey",pub)); obj.push_back(Pair("claim_pubkey",pub));
@@ -1599,7 +1604,7 @@ UniValue GatewaysPendingDeposits(uint256 bindtxid,std::string refcoin)
UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin)
{ {
UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string coin,hex; CPubKey mypk,gatewayspk,withdrawpub,signerpk; UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string coin,hex; CPubKey mypk,gatewayspk,withdrawpub,signerpk;
std::vector<CPubKey> msigpubkeys; uint256 hashBlock,tokenid,txid,tmpbindtxid,tmptokenid,oracletxid,withdrawtxid; uint8_t K,M,N,taddr,prefix,prefix2; std::vector<CPubKey> msigpubkeys; uint256 hashBlock,tokenid,txid,tmpbindtxid,tmptokenid,oracletxid,withdrawtxid; uint8_t K,M,N,taddr,prefix,prefix2,wiftype;
char funcid,depositaddr[65],coinaddr[65],tokensaddr[65],destaddr[65],str[65],withaddr[65],numstr[32],signeraddr[65],txidaddr[65]; char funcid,depositaddr[65],coinaddr[65],tokensaddr[65],destaddr[65],str[65],withaddr[65],numstr[32],signeraddr[65],txidaddr[65];
int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,amount,nValue; struct CCcontract_info *cp,C; int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,amount,nValue; struct CCcontract_info *cp,C;
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
@@ -1615,7 +1620,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin)
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return(""); return("");
} }
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B' || refcoin != coin ) if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2,wiftype) != 'B' || refcoin != coin )
{ {
CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str()); CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str());
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
@@ -1651,12 +1656,12 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin)
continue; continue;
} }
Getscriptaddress(destaddr,tx.vout[1].scriptPubKey); Getscriptaddress(destaddr,tx.vout[1].scriptPubKey);
Getscriptaddress(withaddr,CScript() << ParseHex(HexStr(withdrawpub)) << OP_CHECKSIG); GetCustomscriptaddress(withaddr,CScript() << ParseHex(HexStr(withdrawpub)) << OP_CHECKSIG,taddr,prefix,prefix2);
if ( strcmp(destaddr,tokensaddr) == 0 ) if ( strcmp(destaddr,tokensaddr) == 0 )
{ {
UniValue obj(UniValue::VOBJ); UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("withdrawtxid",uint256_str(str,tx.GetHash()))); obj.push_back(Pair("withdrawtxid",uint256_str(str,tx.GetHash())));
CCtxidaddr(txidaddr,tx.GetHash()); CCCustomtxidaddr(txidaddr,tx.GetHash(),taddr,prefix,prefix2);
obj.push_back(Pair("withdrawtxidaddr",txidaddr)); obj.push_back(Pair("withdrawtxidaddr",txidaddr));
obj.push_back(Pair("withdrawaddr",withaddr)); obj.push_back(Pair("withdrawaddr",withaddr));
sprintf(numstr,"%.8f",(double)tx.vout[1].nValue/COIN); sprintf(numstr,"%.8f",(double)tx.vout[1].nValue/COIN);
@@ -1665,7 +1670,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin)
if ( queueflag != 0 ) if ( queueflag != 0 )
{ {
obj.push_back(Pair("depositaddr",depositaddr)); obj.push_back(Pair("depositaddr",depositaddr));
Getscriptaddress(signeraddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); GetCustomscriptaddress(signeraddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG,taddr,prefix,prefix2);
obj.push_back(Pair("signeraddr",signeraddr)); obj.push_back(Pair("signeraddr",signeraddr));
} }
if (N>1) if (N>1)
@@ -1688,7 +1693,7 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin)
{ {
UniValue result(UniValue::VOBJ),processed(UniValue::VARR); CTransaction tx; std::string coin,hex; UniValue result(UniValue::VOBJ),processed(UniValue::VARR); CTransaction tx; std::string coin,hex;
CPubKey mypk,gatewayspk,withdrawpub; std::vector<CPubKey> msigpubkeys; CPubKey mypk,gatewayspk,withdrawpub; std::vector<CPubKey> msigpubkeys;
uint256 withdrawtxid,hashBlock,txid,tokenid,tmptokenid,oracletxid; uint8_t K,M,N,taddr,prefix,prefix2; uint256 withdrawtxid,hashBlock,txid,tokenid,tmptokenid,oracletxid; uint8_t K,M,N,taddr,prefix,prefix2,wiftype;
char depositaddr[65],coinaddr[65],str[65],numstr[32],withaddr[65],txidaddr[65]; char depositaddr[65],coinaddr[65],str[65],numstr[32],withaddr[65],txidaddr[65];
int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,nValue,amount; struct CCcontract_info *cp,C; int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,nValue,amount; struct CCcontract_info *cp,C;
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
@@ -1703,7 +1708,7 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin)
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return(""); return("");
} }
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B' || refcoin != coin) if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2,wiftype) != 'B' || refcoin != coin)
{ {
CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str()); CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str());
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
@@ -1732,9 +1737,9 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin)
UniValue obj(UniValue::VOBJ); UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("completesigningtxid",uint256_str(str,txid))); obj.push_back(Pair("completesigningtxid",uint256_str(str,txid)));
obj.push_back(Pair("withdrawtxid",uint256_str(str,withdrawtxid))); obj.push_back(Pair("withdrawtxid",uint256_str(str,withdrawtxid)));
CCtxidaddr(txidaddr,withdrawtxid); CCCustomtxidaddr(txidaddr,withdrawtxid,taddr,prefix,prefix2);
obj.push_back(Pair("withdrawtxidaddr",txidaddr)); obj.push_back(Pair("withdrawtxidaddr",txidaddr));
Getscriptaddress(withaddr,CScript() << ParseHex(HexStr(withdrawpub)) << OP_CHECKSIG); GetCustomscriptaddress(withaddr,CScript() << ParseHex(HexStr(withdrawpub)) << OP_CHECKSIG,taddr,prefix,prefix2);
obj.push_back(Pair("withdrawaddr",withaddr)); obj.push_back(Pair("withdrawaddr",withaddr));
obj.push_back(Pair("confirmed_or_notarized",komodo_txnotarizedconfirmed(txid))); obj.push_back(Pair("confirmed_or_notarized",komodo_txnotarizedconfirmed(txid)));
sprintf(numstr,"%.8f",(double)tx.vout[1].nValue/COIN); sprintf(numstr,"%.8f",(double)tx.vout[1].nValue/COIN);
@@ -1752,7 +1757,7 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin)
UniValue GatewaysList() UniValue GatewaysList()
{ {
UniValue result(UniValue::VARR); std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction vintx; std::string coin; int64_t totalsupply; char str[65],depositaddr[64]; uint8_t M,N,taddr,prefix,prefix2; std::vector<CPubKey> pubkeys; UniValue result(UniValue::VARR); std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction vintx; std::string coin; int64_t totalsupply; char str[65],depositaddr[64]; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> pubkeys;
cp = CCinit(&C,EVAL_GATEWAYS); cp = CCinit(&C,EVAL_GATEWAYS);
SetCCtxids(addressIndex,cp->unspendableCCaddr); SetCCtxids(addressIndex,cp->unspendableCCaddr);
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++)
@@ -1760,7 +1765,7 @@ UniValue GatewaysList()
txid = it->first.txhash; txid = it->first.txhash;
if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) if ( GetTransaction(txid,vintx,hashBlock,false) != 0 )
{ {
if ( vintx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,vintx.vout[vintx.vout.size()-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 0 ) if ( vintx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,vintx.vout[vintx.vout.size()-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 0 )
{ {
result.push_back(uint256_str(str,txid)); result.push_back(uint256_str(str,txid));
} }
@@ -1769,11 +1774,60 @@ UniValue GatewaysList()
return(result); return(result);
} }
UniValue GatewaysExternalAddress(uint256 bindtxid,CPubKey pubkey)
{
UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction tx;
std::string coin; int64_t numvouts,totalsupply; char str[65],addr[65],depositaddr[65]; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> msigpubkeys;
cp = CCinit(&C,EVAL_GATEWAYS);
if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 )
{
CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid));
LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return("");
}
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2,wiftype) != 'B')
{
CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str());
LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return("");
}
GetCustomscriptaddress(addr,CScript() << ParseHex(HexStr(pubkey)) << OP_CHECKSIG,taddr,prefix,prefix2);
result.push_back(Pair("result","success"));
result.push_back(Pair("address",addr));
return(result);
}
UniValue GatewaysDumpPrivKey(uint256 bindtxid,CKey key)
{
UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction tx;
std::string coin,priv; int64_t numvouts,totalsupply; char str[65],addr[65],depositaddr[65]; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> msigpubkeys;
cp = CCinit(&C,EVAL_GATEWAYS);
if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 )
{
CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid));
LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return("");
}
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2,wiftype) != 'B')
{
CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str());
LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return("");
}
priv=EncodeCustomSecret(key,wiftype);
result.push_back(Pair("result","success"));
result.push_back(Pair("address",priv.c_str()));
return(result);
}
UniValue GatewaysInfo(uint256 bindtxid) UniValue GatewaysInfo(uint256 bindtxid)
{ {
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::string coin; char str[67],numstr[65],depositaddr[64],gatewaystokens[64]; UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::string coin; char str[67],numstr[65],depositaddr[64],gatewaystokens[64];
uint8_t M,N; std::vector<CPubKey> pubkeys; uint8_t taddr,prefix,prefix2; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; uint8_t M,N; std::vector<CPubKey> pubkeys; uint8_t taddr,prefix,prefix2,wiftype; uint256 tokenid,oracletxid,hashBlock; CTransaction tx;
CPubKey Gatewayspk; struct CCcontract_info *cp,C; int32_t i; int64_t numvouts,totalsupply,remaining; std::vector<CPubKey> msigpubkeys; CPubKey Gatewayspk; struct CCcontract_info *cp,C; int32_t i; int64_t numvouts,totalsupply,remaining; std::vector<CPubKey> msigpubkeys;
cp = CCinit(&C,EVAL_GATEWAYS); cp = CCinit(&C,EVAL_GATEWAYS);
@@ -1785,7 +1839,7 @@ UniValue GatewaysInfo(uint256 bindtxid)
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
return(""); return("");
} }
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B') if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2,wiftype) != 'B')
{ {
CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str()); CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str());
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); LogPrint("gatewayscc","%s\n", CCerror.c_str() );
@@ -1796,7 +1850,7 @@ UniValue GatewaysInfo(uint256 bindtxid)
result.push_back(Pair("result","success")); result.push_back(Pair("result","success"));
result.push_back(Pair("name","Gateways")); result.push_back(Pair("name","Gateways"));
depositaddr[0] = 0; depositaddr[0] = 0;
if ( tx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,tx.vout[tx.vout.size()-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 0 && M <= N && N > 0 ) if ( tx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,tx.vout[tx.vout.size()-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 0 && M <= N && N > 0 )
{ {
if ( N > 1 ) if ( N > 1 )
{ {

View File

@@ -206,6 +206,19 @@ std::string EncodeSecret(const CKey& key)
return ret; return ret;
} }
std::string EncodeCustomSecret(const CKey& key,uint8_t secret_key)
{
assert(key.IsValid());
std::vector<unsigned char> data = std::vector<unsigned char>(1,secret_key);;
data.insert(data.end(), key.begin(), key.end());
if (key.IsCompressed()) {
data.push_back(1);
}
std::string ret = EncodeBase58Check(data);
memory_cleanse(data.data(), data.size());
return ret;
}
CExtPubKey DecodeExtPubKey(const std::string& str) CExtPubKey DecodeExtPubKey(const std::string& str)
{ {
CExtPubKey key; CExtPubKey key;

View File

@@ -18,6 +18,7 @@
CKey DecodeSecret(const std::string& str); CKey DecodeSecret(const std::string& str);
std::string EncodeSecret(const CKey& key); std::string EncodeSecret(const CKey& key);
std::string EncodeCustomSecret(const CKey& key,uint8_t secret_key);
CExtKey DecodeExtKey(const std::string& str); CExtKey DecodeExtKey(const std::string& str);
std::string EncodeExtKey(const CExtKey& extkey); std::string EncodeExtKey(const CExtKey& extkey);

View File

@@ -470,6 +470,8 @@ static const CRPCCommand vRPCCommands[] =
// Gateways // Gateways
{ "gateways", "gatewaysaddress", &gatewaysaddress, true }, { "gateways", "gatewaysaddress", &gatewaysaddress, true },
{ "gateways", "gatewayslist", &gatewayslist, true }, { "gateways", "gatewayslist", &gatewayslist, true },
{ "gateways", "gatewaysexternaladdress", &gatewaysexternaladdress, true },
{ "gateways", "gatewaysdumpprivkey", &gatewaysdumpprivkey, true },
{ "gateways", "gatewaysinfo", &gatewaysinfo, true }, { "gateways", "gatewaysinfo", &gatewaysinfo, true },
{ "gateways", "gatewaysbind", &gatewaysbind, true }, { "gateways", "gatewaysbind", &gatewaysbind, true },
{ "gateways", "gatewaysdeposit", &gatewaysdeposit, true }, { "gateways", "gatewaysdeposit", &gatewaysdeposit, true },

View File

@@ -293,6 +293,8 @@ extern UniValue cclib(const UniValue& params, bool fHelp);
extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp);
extern UniValue gatewayslist(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp);
extern UniValue gatewaysinfo(const UniValue& params, bool fHelp); extern UniValue gatewaysinfo(const UniValue& params, bool fHelp);
extern UniValue gatewaysdumpprivkey(const UniValue& params, bool fHelp);
extern UniValue gatewaysexternaladdress(const UniValue& params, bool fHelp);
extern UniValue gatewaysbind(const UniValue& params, bool fHelp); extern UniValue gatewaysbind(const UniValue& params, bool fHelp);
extern UniValue gatewaysdeposit(const UniValue& params, bool fHelp); extern UniValue gatewaysdeposit(const UniValue& params, bool fHelp);
extern UniValue gatewaysclaim(const UniValue& params, bool fHelp); extern UniValue gatewaysclaim(const UniValue& params, bool fHelp);

View File

@@ -6148,6 +6148,47 @@ UniValue gatewayslist(const UniValue& params, bool fHelp)
return(GatewaysList()); return(GatewaysList());
} }
UniValue gatewaysexternaladdress(const UniValue& params, bool fHelp)
{
uint256 bindtxid; CPubKey pubkey;
if ( fHelp || params.size() != 2)
throw runtime_error("gatewaysexternaladdress bindtxid 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");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
bindtxid = Parseuint256((char *)params[0].get_str().c_str());
pubkey = ParseHex(params[1].get_str().c_str());
return(GatewaysExternalAddress(bindtxid,pubkey));
}
UniValue gatewaysdumpprivkey(const UniValue& params, bool fHelp)
{
uint256 bindtxid;
if ( fHelp || params.size() != 2)
throw runtime_error("gatewaysexternaladdress bindtxid address\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");
LOCK2(cs_main, pwalletMain->cs_wallet);
bindtxid = Parseuint256((char *)params[0].get_str().c_str());
std::string strAddress = params[1].get_str();
CTxDestination dest = DecodeDestination(strAddress);
if (!IsValidDestination(dest)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid transparent address");
}
const CKeyID *keyID = boost::get<CKeyID>(&dest);
if (!keyID) {
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key");
}
CKey vchSecret;
if (!pwalletMain->GetKey(*keyID, vchSecret)) {
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");
}
return(GatewaysDumpPrivKey(bindtxid,vchSecret));
}
UniValue gatewaysinfo(const UniValue& params, bool fHelp) UniValue gatewaysinfo(const UniValue& params, bool fHelp)
{ {
uint256 txid; uint256 txid;
@@ -6163,10 +6204,19 @@ UniValue gatewaysinfo(const UniValue& params, bool fHelp)
UniValue gatewaysbind(const UniValue& params, bool fHelp) UniValue gatewaysbind(const UniValue& params, bool fHelp)
{ {
<<<<<<< HEAD
UniValue result(UniValue::VOBJ); uint256 tokenid,oracletxid; int32_t i; int64_t totalsupply; std::vector<CPubKey> pubkeys; uint8_t M,N; std::string hex,coin; std::vector<unsigned char> pubkey; UniValue result(UniValue::VOBJ); uint256 tokenid,oracletxid; int32_t i; int64_t totalsupply; std::vector<CPubKey> pubkeys; uint8_t M,N; std::string hex,coin; std::vector<unsigned char> pubkey;
if ( fHelp || params.size() < 6 ) if ( fHelp || params.size() < 6 )
throw runtime_error("gatewaysbind tokenid oracletxid coin tokensupply M N pubkey(s)\n"); throw runtime_error("gatewaysbind tokenid oracletxid coin tokensupply M N pubkey(s)\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
=======
UniValue result(UniValue::VOBJ); uint256 tokenid,oracletxid; int32_t i; int64_t totalsupply; std::vector<CPubKey> pubkeys;
uint8_t M,N,p1,p2,p3,p4=0; std::string hex,coin; std::vector<unsigned char> pubkey;
if ( fHelp || params.size() < 9 )
throw runtime_error("gatewaysbind tokenid oracletxid coin tokensupply M N pubkey(s) pubtype p2shtype wiftype [taddr]\n");
if ( ensure_CCrequirements() < 0 )
>>>>>>> FSM
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); 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; const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet); LOCK2(cs_main, pwalletMain->cs_wallet);
@@ -6187,7 +6237,11 @@ UniValue gatewaysbind(const UniValue& params, bool fHelp)
throw runtime_error("invalid destination pubkey"); throw runtime_error("invalid destination pubkey");
pubkeys.push_back(pubkey2pk(pubkey)); pubkeys.push_back(pubkey2pk(pubkey));
} }
hex = GatewaysBind(0,coin,tokenid,totalsupply,oracletxid,M,N,pubkeys); p1 = atoi((char *)params[6+N].get_str().c_str());
p2 = atoi((char *)params[6+N+1].get_str().c_str());
p3 = atoi((char *)params[6+N+2].get_str().c_str());
if (params.size() == 9+N) p4 = atoi((char *)params[6+N+3].get_str().c_str());
hex = GatewaysBind(0,coin,tokenid,totalsupply,oracletxid,M,N,pubkeys,p1,p2,p3,p4);
RETURN_IF_ERROR(CCerror); RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 ) if ( hex.size() > 0 )
{ {