org.bitcoinj.core.ProtocolException Java Examples
The following examples show how to use
org.bitcoinj.core.ProtocolException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ElementsTransactionOutput.java From GreenBits with GNU General Public License v3.0 | 6 votes |
@Override protected void parse() throws ProtocolException { assetTag = readBytes(33); final byte first = readBytes(1)[0]; if (first == 1) { value = (payload[cursor + 7] & 0xffL) | ((payload[cursor + 6] & 0xffL) << 8) | ((payload[cursor + 5] & 0xffL) << 16) | ((payload[cursor + 4] & 0xffL) << 24) | ((payload[cursor + 3] & 0xffL) << 32) | ((payload[cursor + 2] & 0xffL) << 40) | ((payload[cursor + 1] & 0xffL) << 48) | ((payload[cursor] & 0xffL) << 56); cursor += 8; } else { final byte[] commitmentSuffix = readBytes(32); commitment = new byte[33]; commitment[0] = first; System.arraycopy(commitmentSuffix, 0, commitment, 1, 32); } scriptLen = (int) readVarInt(); length = cursor - offset + scriptLen; scriptBytes = readBytes(scriptLen); }
Example #2
Source File: FakeTxBuilder.java From bcm-android with GNU General Public License v3.0 | 5 votes |
/** * Creates two transactions that spend the same (fake) output. t1 spends to "to". t2 spends somewhere else. * The fake output goes to the same address as t2. */ public static DoubleSpends createFakeDoubleSpendTxns(NetworkParameters params, Address to) { DoubleSpends doubleSpends = new DoubleSpends(); Coin value = COIN; Address someBadGuy = LegacyAddress.fromKey(params, new ECKey()); doubleSpends.prevTx = new Transaction(params); TransactionOutput prevOut = new TransactionOutput(params, doubleSpends.prevTx, value, someBadGuy); doubleSpends.prevTx.addOutput(prevOut); doubleSpends.t1 = new Transaction(params); TransactionOutput o1 = new TransactionOutput(params, doubleSpends.t1, value, to); doubleSpends.t1.addOutput(o1); doubleSpends.t1.addInput(prevOut); doubleSpends.t2 = new Transaction(params); doubleSpends.t2.addInput(prevOut); TransactionOutput o2 = new TransactionOutput(params, doubleSpends.t2, value, someBadGuy); doubleSpends.t2.addOutput(o2); try { doubleSpends.t1 = params.getDefaultSerializer().makeTransaction(doubleSpends.t1.bitcoinSerialize()); doubleSpends.t2 = params.getDefaultSerializer().makeTransaction(doubleSpends.t2.bitcoinSerialize()); } catch (ProtocolException e) { throw new RuntimeException(e); } return doubleSpends; }
Example #3
Source File: ElementsSerializer.java From GreenBits with GNU General Public License v3.0 | 5 votes |
public Transaction makeTransaction(final byte[] payloadBytes, final int offset, final int length, final byte[] hash) throws ProtocolException { final Transaction tx = new ElementsTransaction(getParameters(), payloadBytes, offset, null, this, length); if (hash != null) tx.setHash(Sha256Hash.wrapReversed(hash)); return tx; }
Example #4
Source File: BlockHexDeserializer.java From consensusj with Apache License 2.0 | 5 votes |
@Override public Block deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken token = p.getCurrentToken(); switch (token) { case VALUE_STRING: try { byte[] payload = HexUtil.hexStringToByteArray(p.getValueAsString()); // convert to hex return context.getParams().getDefaultSerializer().makeBlock(payload); } catch (ProtocolException e) { throw new InvalidFormatException(p, "Invalid Block", p.getValueAsString(), Block.class); } default: return (Block) ctxt.handleUnexpectedToken(Block.class, p); } }
Example #5
Source File: ElementsTransaction.java From GreenBits with GNU General Public License v3.0 | 4 votes |
public ElementsTransaction(final NetworkParameters params, final byte[] payload, final int offset, final Message parent, final MessageSerializer setSerializer, final int length) throws ProtocolException { super(params, payload, offset, parent, setSerializer, length); outWitness = new ArrayList<>(); }
Example #6
Source File: ElementsTransaction.java From GreenBits with GNU General Public License v3.0 | 4 votes |
protected void parse() throws ProtocolException { final boolean witSupported = (protocolVersion >= NetworkParameters.ProtocolVersion.WITNESS_VERSION.getBitcoinProtocolVersion()) && (transactionOptions & TransactionOptions.WITNESS) != 0; cursor = offset; version = readUint32(); optimalEncodingMessageSize = 4; // First come the inputs. readInputs(); byte flags = 0; if (witSupported && getInputs().isEmpty()) { flags = readBytes(1)[0]; optimalEncodingMessageSize += 1; if (flags != 0) { readInputs(); readOutputs(); } else { outputs = new ArrayList<>(0); } } else { readOutputs(); } if (((flags & 1) != 0) && witSupported) { flags ^= 1; readWitness(); } if (((flags & 2) != 0) && witSupported) { flags ^= 2; readOutWitness(); } if (flags != 0) { throw new ProtocolException("Unknown transaction optional data"); } lockTime = readUint32(); optimalEncodingMessageSize += 4; length = cursor - offset; witnesses = witnesses == null ? new ArrayList<TransactionWitness>() : witnesses; }
Example #7
Source File: ElementsTransactionOutput.java From GreenBits with GNU General Public License v3.0 | 4 votes |
public ElementsTransactionOutput(final NetworkParameters params, final Transaction parent, final byte[] payload, final int offset, final MessageSerializer serializer) throws ProtocolException { super(params, parent, payload, offset, serializer); }