/****************************************************************************** * Copyright © 2014-2018 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * * holder information and the developer policies on copyright and licensing. * * * * Unless otherwise agreed in a custom licensing agreement, no part of the * * SuperNET software, including this file may be copied, modified, propagated * * or distributed except according to the terms contained in the LICENSE file * * * * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ #include "CCinclude.h" /* CCutils has low level functions that are universally useful for all contracts. */ CTxOut MakeCC1vout(uint8_t evalcode,CAmount nValue,CPubKey pk) { CTxOut vout; CC *payoutCond = MakeCCcond1(evalcode,pk); vout = CTxOut(nValue,CCPubKey(payoutCond)); cc_free(payoutCond); return(vout); } CC *MakeCCcond1(uint8_t evalcode,CPubKey pk) { std::vector pks; pks.push_back(CCNewSecp256k1(pk)); CC *condCC = CCNewEval(E_MARSHAL(ss << evalcode)); CC *Sig = CCNewThreshold(1, pks); return CCNewThreshold(2, {condCC, Sig}); } CC* GetCryptoCondition(CScript const& scriptSig) { auto pc = scriptSig.begin(); opcodetype opcode; std::vector ffbin; if (scriptSig.GetOp(pc, opcode, ffbin)) return cc_readFulfillmentBinary((uint8_t*)ffbin.data(), ffbin.size()-1); } bool IsCCInput(CScript const& scriptSig) { CC *cond; if ( (cond= GetCryptoCondition(scriptSig)) == 0 ) return false; cc_free(cond); return true; } uint256 revuint256(uint256 txid) { uint256 revtxid; int32_t i; for (i=31; i>=0; i--) ((uint8_t *)&revtxid)[31-i] = ((uint8_t *)&txid)[i]; return(revtxid); } char *uint256_str(char *dest,uint256 txid) { int32_t i,j=0; for (i=31; i>=0; i--) sprintf(&dest[j++ * 2],"%02x",((uint8_t *)&txid)[i]); return(dest); } uint256 Parseuint256(char *hexstr) { uint256 txid; int32_t i; std::vector txidbytes(ParseHex(hexstr)); memset(&txid,0,sizeof(txid)); if ( strlen(hexstr) == 64 ) { for (i=31; i>=0; i--) ((uint8_t *)&txid)[31-i] = ((uint8_t *)txidbytes.data())[i]; } return(txid); } CPubKey pubkey2pk(std::vector pubkey) { CPubKey pk; int32_t i,n; uint8_t *dest,*pubkey33; n = pubkey.size(); dest = (uint8_t *)pk.begin(); pubkey33 = (uint8_t *)pubkey.data(); for (i=0; i= 0 ) { for (i=preventCCvins; iInvalid("invalid CC vin"); } } if ( preventCCvouts >= 0 ) { for (i=preventCCvouts; iInvalid("invalid CC vout"); } } return(true); } std::vector Mypubkey() { extern uint8_t NOTARY_PUBKEY33[33]; std::vector pubkey; int32_t i; uint8_t *dest,*pubkey33; pubkey33 = NOTARY_PUBKEY33; pubkey.resize(33); dest = pubkey.data(); for (i=0; i<33; i++) dest[i] = pubkey33[i]; return(pubkey); } bool Myprivkey(uint8_t myprivkey[]) { char coinaddr[64]; std::string strAddress; char *dest; int32_t i,n; CBitcoinAddress address; CKeyID keyID; CKey vchSecret; if ( Getscriptaddress(coinaddr,CScript() << Mypubkey() << OP_CHECKSIG) != 0 ) { n = (int32_t)strlen(coinaddr); strAddress.resize(n+1); dest = (char *)strAddress.data(); for (i=0; iGetKey(keyID,vchSecret) != 0 ) { memcpy(myprivkey,vchSecret.begin(),32); if ( 0 ) { for (i=0; i<32; i++) fprintf(stderr,"0x%02x, ",myprivkey[i]); fprintf(stderr," found privkey!\n"); } return(true); } #endif } } fprintf(stderr,"privkey for the -pubkey= address is not in the wallet, importprivkey!\n"); return(false); }