After we receive the finalized transaction from the masternode, we must check it to make sure it's what we want, then sign it if we agree. If we refuse to sign, it's possible we'll be charged collateral
| 1240 | // If we refuse to sign, it's possible we'll be charged collateral |
| 1241 | // |
| 1242 | bool CDarkSendPool::SignFinalTransaction(const CTransaction& finalTransactionNew, CNode* node) { |
| 1243 | if (fDebug) LogPrintf("CDarkSendPool::AddFinalTransaction - Got Finalized Transaction\n"); |
| 1244 | |
| 1245 | if (!finalTransaction.vin.empty()) { |
| 1246 | LogPrintf("CDarkSendPool::AddFinalTransaction - Rejected Final Transaction!\n"); |
| 1247 | return false; |
| 1248 | } |
| 1249 | |
| 1250 | finalTransaction = finalTransactionNew; |
| 1251 | LogPrintf("CDarkSendPool::SignFinalTransaction %s\n", finalTransaction.ToString().c_str()); |
| 1252 | |
| 1253 | vector <CTxIn> sigs; |
| 1254 | |
| 1255 | //make sure my inputs/outputs are present, otherwise refuse to sign |
| 1256 | for (const CDarkSendEntry e : myEntries) { |
| 1257 | for (const CDarkSendEntryVin s : e.sev) { |
| 1258 | /* Sign my transaction and all outputs */ |
| 1259 | int mine = -1; |
| 1260 | CScript prevPubKey = CScript(); |
| 1261 | CTxIn vin = CTxIn(); |
| 1262 | |
| 1263 | for (unsigned int i = 0; i < finalTransaction.vin.size(); i++) { |
| 1264 | if (finalTransaction.vin[i] == s.vin) { |
| 1265 | mine = i; |
| 1266 | prevPubKey = s.vin.prevPubKey; |
| 1267 | vin = s.vin; |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | if (mine >= 0) { //might have to do this one input at a time? |
| 1272 | int foundOutputs = 0; |
| 1273 | int64_t nValue1 = 0; |
| 1274 | int64_t nValue2 = 0; |
| 1275 | |
| 1276 | for (unsigned int i = 0; i < finalTransaction.vout.size(); i++) { |
| 1277 | for (const CTxOut o : e.vout) { |
| 1278 | if (finalTransaction.vout[i] == o) { |
| 1279 | foundOutputs++; |
| 1280 | nValue1 += finalTransaction.vout[i].nValue; |
| 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | for (const CTxOut o : e.vout) |
| 1286 | nValue2 += o.nValue; |
| 1287 | |
| 1288 | int targetOuputs = e.vout.size(); |
| 1289 | if (foundOutputs < targetOuputs || nValue1 != nValue2) { |
| 1290 | // in this case, something went wrong and we'll refuse to sign. It's possible we'll be charged collateral. But that's |
| 1291 | // better then signing if the transaction doesn't look like what we wanted. |
| 1292 | LogPrintf("CDarkSendPool::Sign - My entries are not correct! Refusing to sign. %d entries %d target. \n", foundOutputs, targetOuputs); |
| 1293 | return false; |
| 1294 | } |
| 1295 | |
| 1296 | if (fDebug) LogPrintf("CDarkSendPool::Sign - Signing my input %i\n", mine); |
| 1297 | const CAmount& amount = finalTransaction.vout[finalTransaction.vin[mine].prevout.n].nValue; |
| 1298 | SignatureData sigdata; |
| 1299 | bool isSigned = ProduceSignature(MutableTransactionSignatureCreator(pwalletMain, &finalTransaction, (unsigned int) mine, amount, SIGHASH_ALL), prevPubKey, sigdata); // changes scriptSig |
no test coverage detected