/* This method is commonly used by the node to determine if the transaction has * the correct mixin (anonymity) as defined by the current rules */ public static Tuple <bool, string> validate(CachedTransaction transaction, ulong minMixin, ulong maxMixin) { ulong ringSize = 1; var tx = createTransaction(transaction.getTransaction()); for (uint i = 0; i < tx.getInputCount(); ++i) { if (tx.getInputType(i) != TransactionTypes.InputType.Key) { continue; } KeyInput input = new KeyInput(); tx.getInput(i, input); ulong currentRingSize = input.outputIndexes.Count; if (currentRingSize > ringSize) { ringSize = currentRingSize; } } /* Ring size = mixin + 1 - your transaction plus the others you mix with */ ulong mixin = ringSize - 1; std::stringstream str = new std::stringstream(); if (mixin > maxMixin) { str << "Transaction " << transaction.getTransactionHash() << " is not valid. Reason: transaction mixin is too large (" << (int)mixin << "). Maximum mixin allowed is " << (int)maxMixin; return(new Tuple <bool, string>(false, str.str())); } else if (mixin < minMixin) { str << "Transaction " << transaction.getTransactionHash() << " is not valid. Reason: transaction mixin is too small (" << (int)mixin << "). Minimum mixin allowed is " << (int)minMixin; return(new Tuple <bool, string>(false, str.str())); } return(new Tuple <bool, string>(true, string())); }
//-------------------------------------------------------------------------------- private bool print_tx(List <string> args) { if (args.Count == 0) { Console.Write("expected: print_tx <transaction hash>"); Console.Write("\n"); return(true); } string str_hash = args[0]; Crypto.Hash tx_hash = new Crypto.Hash(); if (!parse_hash256(str_hash, tx_hash)) { return(true); } List <Crypto.Hash> tx_ids = new List <Crypto.Hash>(); tx_ids.Add(tx_hash); List <List <ushort> > txs = new List <List <ushort> >(); List <Crypto.Hash> missed_ids = new List <Crypto.Hash>(); m_core.getTransactions(tx_ids, txs, missed_ids); if (1 == txs.Count) { CryptoNote.CachedTransaction tx = new CryptoNote.CachedTransaction(new List <List <ushort> >(txs[0])); GlobalMembers.print_as_json(tx.getTransaction()); } else { Console.Write("transaction wasn't found: <"); Console.Write(str_hash); Console.Write('>'); Console.Write("\n"); } return(true); }