Java Code Examples for com.btchip.utils.BufferUtils#writeUint32LE()
The following examples show how to use
com.btchip.utils.BufferUtils#writeUint32LE() .
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: BTChipHWWallet.java From green_android with GNU General Public License v3.0 | 5 votes |
private byte[] inputBytes(final InputOutputData in, final boolean isSegwit) { final ByteArrayOutputStream os = new ByteArrayOutputStream(32 + (isSegwit ? 12 : 4)); final byte[] txid = in.getTxid(); os.write(txid, 0, txid.length); BufferUtils.writeUint32LE(os, in.getPtIdx()); if (isSegwit) BufferUtils.writeUint64LE(os, in.getSatoshi()); return os.toByteArray(); }
Example 2
Source File: BTChipHWWallet.java From green_android with GNU General Public License v3.0 | 5 votes |
private byte[] inputLiquidBytes(final InputOutputData in) { final ByteArrayOutputStream os = new ByteArrayOutputStream(32 + 4 + 33); final byte[] txid = in.getTxid(); os.write(txid, 0, txid.length); BufferUtils.writeUint32LE(os, in.getPtIdx()); os.write(in.getCommitmentBytes(), 0, in.getCommitmentBytes().length); return os.toByteArray(); }
Example 3
Source File: BTChipDongle.java From GreenBits with GNU General Public License v3.0 | 5 votes |
public BTChipInput getTrustedInput(BitcoinTransaction transaction, long index, long sequence) throws BTChipException { ByteArrayOutputStream data = new ByteArrayOutputStream(); // Header BufferUtils.writeUint32BE(data, index); BufferUtils.writeBuffer(data, transaction.getVersion()); VarintUtils.write(data, transaction.getInputs().size()); exchangeApdu(BTCHIP_CLA, BTCHIP_INS_GET_TRUSTED_INPUT, (byte)0x00, (byte)0x00, data.toByteArray(), OK); // Each input for (BitcoinTransaction.BitcoinInput input : transaction.getInputs()) { data = new ByteArrayOutputStream(); BufferUtils.writeBuffer(data, input.getPrevOut()); VarintUtils.write(data, input.getScript().length); exchangeApdu(BTCHIP_CLA, BTCHIP_INS_GET_TRUSTED_INPUT, (byte)0x80, (byte)0x00, data.toByteArray(), OK); data = new ByteArrayOutputStream(); BufferUtils.writeBuffer(data, input.getScript()); exchangeApduSplit2(BTCHIP_CLA, BTCHIP_INS_GET_TRUSTED_INPUT, (byte)0x80, (byte)0x00, data.toByteArray(), input.getSequence(), OK); } // Number of outputs data = new ByteArrayOutputStream(); VarintUtils.write(data, transaction.getOutputs().size()); exchangeApdu(BTCHIP_CLA, BTCHIP_INS_GET_TRUSTED_INPUT, (byte)0x80, (byte)0x00, data.toByteArray(), OK); // Each output for (BitcoinTransaction.BitcoinOutput output : transaction.getOutputs()) { data = new ByteArrayOutputStream(); BufferUtils.writeBuffer(data, output.getAmount()); VarintUtils.write(data, output.getScript().length); exchangeApdu(BTCHIP_CLA, BTCHIP_INS_GET_TRUSTED_INPUT, (byte)0x80, (byte)0x00, data.toByteArray(), OK); data = new ByteArrayOutputStream(); BufferUtils.writeBuffer(data, output.getScript()); exchangeApduSplit(BTCHIP_CLA, BTCHIP_INS_GET_TRUSTED_INPUT, (byte)0x80, (byte)0x00, data.toByteArray(), OK); } // Locktime byte[] response = exchangeApdu(BTCHIP_CLA, BTCHIP_INS_GET_TRUSTED_INPUT, (byte)0x80, (byte)0x00, transaction.getLockTime(), OK); ByteArrayOutputStream sequenceBuf = new ByteArrayOutputStream(); BufferUtils.writeUint32LE(sequenceBuf, sequence); return new BTChipInput(response, sequenceBuf.toByteArray(), true, false); }
Example 4
Source File: BTChipDongle.java From WalletCordova with GNU Lesser General Public License v2.1 | 5 votes |
public BTChipInput getTrustedInput(BitcoinTransaction transaction, long index, long sequence) throws BTChipException { ByteArrayOutputStream data = new ByteArrayOutputStream(); // Header BufferUtils.writeUint32BE(data, index); BufferUtils.writeBuffer(data, transaction.getVersion()); VarintUtils.write(data, transaction.getInputs().size()); exchangeApdu(BTCHIP_CLA, BTCHIP_INS_GET_TRUSTED_INPUT, (byte)0x00, (byte)0x00, data.toByteArray(), OK); // Each input for (BitcoinTransaction.BitcoinInput input : transaction.getInputs()) { data = new ByteArrayOutputStream(); BufferUtils.writeBuffer(data, input.getPrevOut()); VarintUtils.write(data, input.getScript().length); exchangeApdu(BTCHIP_CLA, BTCHIP_INS_GET_TRUSTED_INPUT, (byte)0x80, (byte)0x00, data.toByteArray(), OK); data = new ByteArrayOutputStream(); BufferUtils.writeBuffer(data, input.getScript()); exchangeApduSplit2(BTCHIP_CLA, BTCHIP_INS_GET_TRUSTED_INPUT, (byte)0x80, (byte)0x00, data.toByteArray(), input.getSequence(), OK); } // Number of outputs data = new ByteArrayOutputStream(); VarintUtils.write(data, transaction.getOutputs().size()); exchangeApdu(BTCHIP_CLA, BTCHIP_INS_GET_TRUSTED_INPUT, (byte)0x80, (byte)0x00, data.toByteArray(), OK); // Each output for (BitcoinTransaction.BitcoinOutput output : transaction.getOutputs()) { data = new ByteArrayOutputStream(); BufferUtils.writeBuffer(data, output.getAmount()); VarintUtils.write(data, output.getScript().length); exchangeApdu(BTCHIP_CLA, BTCHIP_INS_GET_TRUSTED_INPUT, (byte)0x80, (byte)0x00, data.toByteArray(), OK); data = new ByteArrayOutputStream(); BufferUtils.writeBuffer(data, output.getScript()); exchangeApduSplit(BTCHIP_CLA, BTCHIP_INS_GET_TRUSTED_INPUT, (byte)0x80, (byte)0x00, data.toByteArray(), OK); } // Locktime byte[] response = exchangeApdu(BTCHIP_CLA, BTCHIP_INS_GET_TRUSTED_INPUT, (byte)0x80, (byte)0x00, transaction.getLockTime(), OK); ByteArrayOutputStream sequenceBuf = new ByteArrayOutputStream(); BufferUtils.writeUint32LE(sequenceBuf, sequence); return new BTChipInput(response, sequenceBuf.toByteArray(), true); }
Example 5
Source File: BTChipHWWallet.java From green_android with GNU General Public License v3.0 | 4 votes |
private byte[] sequenceBytes(final InputOutputData in) { final ByteArrayOutputStream os = new ByteArrayOutputStream(4); BufferUtils.writeUint32LE(os, in.getSequence()); return os.toByteArray(); }