/**
		 * Creates an UNSIGNED input that links to the given output
		 */
		TransactionInput(NetworkParameters params, Transaction parentTransaction, TransactionOutput output) {
			super(params);
			long outputIndex = output.getIndex();
			outpoint = new TransactionOutPoint(params, outputIndex, output.parentTransaction);
			scriptBytes = EMPTY_ARRAY;
			sequence = NO_SEQUENCE;
			this.parentTransaction = parentTransaction;

			length = 41;
		}
Beispiel #2
0
        /**
         * Creates an UNSIGNED input that links to the given output
         */
        TransactionInput(NetworkParameters params, Transaction parentTransaction, TransactionOutput output)
        {
            super(params);
            long outputIndex = output.getIndex();

            outpoint               = new TransactionOutPoint(params, outputIndex, output.parentTransaction);
            scriptBytes            = EMPTY_ARRAY;
            sequence               = NO_SEQUENCE;
            this.parentTransaction = parentTransaction;

            length = 41;
        }
Beispiel #3
0
		/**
		 * Adds the given output to this transaction. The output must be completely initialized.
		 */
		public void addOutput(TransactionOutput to)
		{
			unCache();
			to.setParent(this);
			outputs.add(to);
			adjustLength(outputs.size(), to.length);
		}
Beispiel #4
0
		//public String toString() {
		//	return toString(null);
		//}

		///**
		// * A human readable version of the transaction useful for debugging. The format is not guaranteed to be stable.
		// * @param chain If provided, will be used to estimate lock times (if set). Can be null.
		// */
		//public String toString(ABlockChain chain)
		//{
		//	// Basic info about the tx.
		//	StringBuilder s=new StringBuilder();
		//	s.Append(string.Format("  {0}: {1}", getHashAsString(), getConfidence()));
		//	if (lockTime > 0) {
		//		String time;
		//		if (lockTime < LocktimeThreshold) {
		//			time = "block " + lockTime;
		//			if (chain != null) {
		//				time = time + " (estimated to be reached at " +
		//						chain.estimateBlockTime((int)lockTime).toString() + ")";
		//			}
		//		} else {
		//			time = new Date(lockTime).toString();
		//		}
		//		s.append(String.format("  time locked until %s%n", time));
		//	}
		//	if (inputs.size() == 0) {
		//		s.append(String.format("  INCOMPLETE: No inputs!%n"));
		//		return s.toString();
		//	}
		//	if (isCoinBase()) {
		//		String script;
		//		String script2;
		//		try {
		//			script = inputs.get(0).getScriptSig().toString();
		//			script2 = outputs.get(0).getScriptPubKey().toString();
		//		} catch (ScriptException e) {
		//			script = "???";
		//			script2 = "???";
		//		}
		//		return "     == COINBASE TXN (scriptSig " + script + ")  (scriptPubKey " + script2 + ")\n";
		//	}
		//	for (TransactionInput in : inputs) {
		//		s.append("     ");
		//		s.append("from ");

		//		try {
		//			Script scriptSig = in.getScriptSig();
		//			if (scriptSig.chunks.size() == 2)
		//				s.append(scriptSig.getFromAddress().toString());
		//			else if (scriptSig.chunks.size() == 1)
		//				s.append("[sig:" + bytesToHexString(scriptSig.getPubKey()) + "]");
		//			else
		//				s.append("???");
		//			s.append(" / ");
		//			s.append(in.getOutpoint().toString());
		//		} catch (Exception e) {
		//			s.append("[exception: ").append(e.getMessage()).append("]");
		//		}
		//		s.append(String.format("%n"));
		//	}
		//	for (TransactionOutput out : outputs) {
		//		s.append("       ");
		//		s.append("to ");
		//		try {
		//			Script scriptPubKey = out.getScriptPubKey();
		//			if (scriptPubKey.isSentToAddress()) {
		//				s.append(scriptPubKey.getToAddress().toString());
		//			} else if (scriptPubKey.isSentToRawPubKey()) {
		//				s.append("[pubkey:");
		//				s.append(bytesToHexString(scriptPubKey.getPubKey()));
		//				s.append("]");
		//			}
		//			s.append(" ");
		//			s.append(bitcoinValueToFriendlyString(out.getValue()));
		//			s.append(" BTC");
		//			if (!out.isAvailableForSpending()) {
		//				s.append(" Spent");
		//			}
		//			if (out.getSpentBy() != null) {
		//				s.append(" by ");
		//				s.append(out.getSpentBy().getParentTransaction().getHashAsString());
		//			}
		//		} catch (Exception e) {
		//			s.append("[exception: ").append(e.getMessage()).append("]");
		//		}
		//		s.append(String.format("%n"));
		//	}
		//	return s.toString();
		//}

		/**
		 * Adds an input to this transaction that imports value from the given output. Note that this input is NOT
		 * complete and after every input is added with addInput() and every output is added with addOutput(),
		 * signInputs() must be called to finalize the transaction and finish the inputs off. Otherwise it won't be
		 * accepted by the network.
		 */
		public void addInput(TransactionOutput from)
		{ addInput(new TransactionInput(Parameters,this,from)); }