Skip to content

Commit

Permalink
Merge Oracles V2 (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixa84 authored and dimxy committed Dec 23, 2021
1 parent fa9e80d commit 480d50e
Show file tree
Hide file tree
Showing 9 changed files with 649 additions and 353 deletions.
2 changes: 1 addition & 1 deletion src/cc/CCcustom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ uint8_t KogsCCpriv[32] = { 0x9f, 0x9a, 0x85, 0x6d, 0xd9, 0x2b, 0xfe, 0xcb, 0xa1,
// OraclesV2
#define FUNCNAME IsOraclesV2Input
#define EVALCODE EVAL_ORACLESV2
const char *OraclesV2CCaddr = "RBPhbiVUoyvDuLc7ZdFHqzar8t8jtQdKC4";
const char *OraclesV2CCaddr = "RJgkaZ2e5Ygw8eKJHNozp2en7sdBj4Bw17";
const char *OraclesV2Normaladdr = "RPKeRunEv8FwfFGxU3SoC1W4gEDgUBqUaS";
char OraclesV2CChexstr[67] = { "02c03cdb8822daa30241cc137fbbee76ead55d7f92e667df1c8ce56e6e50824386" };
uint8_t OraclesV2CCpriv[32] = { 0x18, 0x6A, 0xE7, 0x8C, 0x0E, 0x03, 0x3C, 0x5D, 0x6C, 0xE7, 0xE9, 0x8E, 0x0A, 0xCA, 0x94, 0x69, 0x6A, 0xEC, 0x5C, 0x84, 0x09, 0x28, 0xD4, 0x37, 0x17, 0xAF, 0xEF, 0x35, 0x3A, 0x0E, 0x19, 0x3F };
Expand Down
2 changes: 1 addition & 1 deletion src/cc/CCtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ UniValue FinalizeCCV2Tx(bool remote, uint64_t mask, struct CCcontract_info *cp,
if ( !(mask & FINALIZECCTX_NO_CHANGE) && totalinputs >= totaloutputs+txfee )
{
change = totalinputs - (totaloutputs+txfee);
if (!(mask & FINALIZECCTX_NO_CHANGE_WHEN_ZERO)) mtx.vout.push_back(CTxOut(change,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
if (!(mask & FINALIZECCTX_NO_CHANGE_WHEN_ZERO) || change>0 ) mtx.vout.push_back(CTxOut(change,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
}
if ( opret.size() > 0 )
mtx.vout.push_back(CTxOut(0,opret));
Expand Down
2 changes: 1 addition & 1 deletion src/cc/CCvalidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ bool ValidateNormalVins(Eval* eval, const CTransaction& tx,int32_t index)
{
for (int i=index;i<tx.vin.size();i++)
if (IsCCInput(tx.vin[i].scriptSig) != 0 )
return eval->Invalid("vin."+std::to_string(i)+" is normal for channel tx!");
return eval->Invalid("vin."+std::to_string(i)+" is normal for this tx!");
return (true);
}

Expand Down
728 changes: 435 additions & 293 deletions src/cc/channels.cpp

Large diffs are not rendered by default.

182 changes: 133 additions & 49 deletions src/cc/oraclesV2.cpp

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/cryptoconditions/src/anon.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ CC* cc_anon(const CC *cond) {
out->cost = cc_getCost(cond);
out->subtypes = cond->type->getSubtypes(cond);

unsigned char *fp = cond->type->fingerprint(cond);
unsigned char *fp = calloc(1, 32);
cond->type->fingerprint(cond,fp);
memcpy(out->fingerprint, fp, 32);
free(fp);
return out;
Expand Down
4 changes: 2 additions & 2 deletions src/cryptoconditions/tests/test_failure_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def test_malleability_checked():


def test_large_threshold():
return
conds = [{
'type': "secp256k1-sha-256",
"publicKey": "02D5D969305535AC29A77079C11D4F0DD40661CF96E04E974A5E8D7E374EE225AA"
}]



for i in range(250):
conds.append({
"type": "eval-sha-256",
Expand Down
9 changes: 5 additions & 4 deletions src/script/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,13 @@ bool CScript::IsPayToCryptoCondition(CScript *pCCSubScript, std::vector<std::vec
{
const_iterator pc = begin();
vector<unsigned char> data;
opcodetype opcode;
opcodetype opcode,opcode1;
if (this->GetOp(pc, opcode, data))
// Sha256 conditions are <76 bytes
if (opcode > OP_0 && opcode < OP_PUSHDATA1)
if (this->GetOp(pc, opcode, data))
if (opcode == OP_CHECKCRYPTOCONDITION)
if (data.size()>0 && (data[0]=='M' || (data[0]!='M' && opcode > OP_0 && opcode < OP_PUSHDATA1)))
//if (opcode > OP_0 && opcode < OP_PUSHDATA1)
if (this->GetOp(pc, opcode1, data))
if (opcode1 == OP_CHECKCRYPTOCONDITION)
{
const_iterator pcCCEnd = pc;
if (GetBalancedData(pc, vParams))
Expand Down
70 changes: 69 additions & 1 deletion src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5698,6 +5698,74 @@ UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector<unsigned ch
return(result);
}

UniValue CCaddressV2(struct CCcontract_info *cp,char *name,std::vector<unsigned char> &pubkey)
{
UniValue result(UniValue::VOBJ); char destaddr[64],str[64]; CPubKey mypk,pk;
pk = GetUnspendable(cp,0);
GetCCaddress(cp,destaddr,pk,true);
if ( strcmp(destaddr,cp->unspendableCCaddr) != 0 )
{
uint8_t priv[32];
Myprivkey(priv); // it is assumed the CC's normal address'es -pubkey was used
fprintf(stderr,"fix mismatched CCaddr %s -> %s\n",cp->unspendableCCaddr,destaddr);
strcpy(cp->unspendableCCaddr,destaddr);
memset(priv,0,32);
}
result.push_back(Pair("result", "success"));
sprintf(str,"%sCCAddress",name);
result.push_back(Pair(str,cp->unspendableCCaddr));
sprintf(str,"%sCCBalance",name);
result.push_back(Pair(str,ValueFromAmount(CCaddress_balance(cp->unspendableCCaddr,1))));
sprintf(str,"%sNormalAddress",name);
result.push_back(Pair(str,cp->normaladdr));
sprintf(str,"%sNormalBalance",name);
result.push_back(Pair(str,ValueFromAmount(CCaddress_balance(cp->normaladdr,0))));
if (strcmp(name,"Gateways")==0) result.push_back(Pair("GatewaysPubkey","03ea9c062b9652d8eff34879b504eda0717895d27597aaeb60347d65eed96ccb40"));
if ((strcmp(name,"Channels")==0 || strcmp(name,"Heir")==0) && pubkey.size() == 33)
{
sprintf(str,"%sCC1of2Address",name);
mypk = pubkey2pk(Mypubkey());
GetCCaddress1of2(cp,destaddr,mypk,pubkey2pk(pubkey),true);
result.push_back(Pair(str,destaddr));
if (GetTokensCCaddress1of2(cp,destaddr,mypk,pubkey2pk(pubkey))>0)
{
sprintf(str,"%sCC1of2TokensAddress",name);
result.push_back(Pair(str,destaddr));
}
}
else if (strcmp(name,"Tokens")!=0)
{
if (GetTokensCCaddress(cp,destaddr,pk)>0)
{
sprintf(str,"%sCCTokensAddress",name);
result.push_back(Pair(str,destaddr));
}
}
if ( pubkey.size() == 33 )
{
if ( GetCCaddress(cp,destaddr,pubkey2pk(pubkey),true) != 0 )
{
sprintf(str,"PubkeyCCaddress(%s)",name);
result.push_back(Pair(str,destaddr));
sprintf(str,"PubkeyCCbalance(%s)",name);
result.push_back(Pair(str,ValueFromAmount(CCaddress_balance(destaddr,0))));
}
}
if ( GetCCaddress(cp,destaddr,pubkey2pk(Mypubkey()),true) != 0 )
{
sprintf(str,"myCCAddress(%s)",name);
result.push_back(Pair(str,destaddr));
sprintf(str,"myCCbalance(%s)",name);
result.push_back(Pair(str,ValueFromAmount(CCaddress_balance(destaddr,1))));
}
if ( Getscriptaddress(destaddr,(CScript() << Mypubkey() << OP_CHECKSIG)) != 0 )
{
result.push_back(Pair("myaddress",destaddr));
result.push_back(Pair("mybalance",ValueFromAmount(CCaddress_balance(destaddr,0))));
}
return(result);
}

bool pubkey2addr(char *destaddr,uint8_t *pubkey33);

UniValue setpubkey(const UniValue& params, bool fHelp, const CPubKey& mypk)
Expand Down Expand Up @@ -6043,7 +6111,7 @@ UniValue oraclesv2address(const UniValue& params, bool fHelp, const CPubKey& myp
throw runtime_error(CC_REQUIREMENTS_MSG);
if ( params.size() == 1 )
pubkey = ParseHex(params[0].get_str().c_str());
return(CCaddress(cp,(char *)"Oracles V2",pubkey));
return(CCaddressV2(cp,(char *)"Oracles V2",pubkey));
}

UniValue pricesaddress(const UniValue& params, bool fHelp, const CPubKey& mypk)
Expand Down

0 comments on commit 480d50e

Please sign in to comment.