From 823017c122459a0fe234ca2b614916e0353ce7c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 29 Jan 2019 01:45:41 -1100 Subject: [PATCH] Sudokupk signing --- src/cc/sudoku.cpp | 9 +++++++-- src/wallet/rpcwallet.cpp | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index adba75920..336edffcd 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -502,7 +502,7 @@ CScript sudoku_genopret(uint8_t unsolved[9][9]) UniValue sudoku_generate(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); CPubKey sudokupk,pk; uint8_t privkey[32],unsolved[9][9],pub33[33]; uint32_t srandi; uint256 hash; char coinaddr[64]; uint64_t inputsum,amount; std::string rawtx; + UniValue result(UniValue::VOBJ); CPubKey sudokupk,pk; uint8_t privkey[32],unsolved[9][9],pub33[33]; uint32_t srandi; uint256 hash; char coinaddr[64]; uint64_t inputsum,amount,change=0; std::string rawtx; if ( params != 0 ) { printf("params.(%s)\n",jprint(params,0)); @@ -523,7 +523,12 @@ UniValue sudoku_generate(uint64_t txfee,struct CCcontract_info *cp,cJSON *params if ( (inputsum= AddCClibInputs(cp,mtx,sudokupk,amount+2*txfee,16)) >= amount+2*txfee ) { mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,sudokupk)); - mtx.vout.push_back(MakeCC1vout(cp->evalcode,inputsum - 2*txfee,pk)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,pk)); + if ( inputsum > amount + 2*txfee ) + change = (inputsum - amount - 2*txfee); + if ( change > txfee ) + mtx.vout.push_back(MakeCC1vout(cp->evalcode,change,sudokupk)); + CCaddr2set(cp,cp->evalcode,sudokupk,cp->CCpriv,cp->CCaddr); rawtx = FinalizeCCTx(0,cp,mtx,sudokupk,txfee,sudoku_genopret(unsolved)); result.push_back(Pair("hex",rawtx)); } else result.push_back(Pair("error","not enough SUDOKU funds")); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fc1839de2..3409710ad 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5240,7 +5240,10 @@ UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector