org.bitcoinj.core.Transaction.bitcoinSerialize()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(135)

本文整理了Java中org.bitcoinj.core.Transaction.bitcoinSerialize()方法的一些代码示例,展示了Transaction.bitcoinSerialize()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transaction.bitcoinSerialize()方法的具体详情如下:
包路径:org.bitcoinj.core.Transaction
类名称:Transaction
方法名:bitcoinSerialize

Transaction.bitcoinSerialize介绍

暂无

代码示例

代码示例来源:origin: blockchain/thunder

public LNEstablishCMessage (Transaction transaction) {
  this.anchorSigned = transaction.bitcoinSerialize();
}

代码示例来源:origin: Coinomi/coinomi-android

public byte[] bitcoinSerialize() {
  checkState(!isTrimmed, "Cannot serialize a trimmed transaction");
  return tx.bitcoinSerialize();
}

代码示例来源:origin: ConsensusJ/consensusj

@Override
public void serialize(Transaction value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
  gen.writeString(bytesToHexString(value.bitcoinSerialize()));
}

代码示例来源:origin: openwalletGH/openwallet-android

public byte[] bitcoinSerialize() {
  checkState(!isTrimmed, "Cannot serialize a trimmed transaction");
  return tx.bitcoinSerialize();
}

代码示例来源:origin: DanielKrawisz/Shufflepuff

@Override
public Bytestring serialize() {
  return new Bytestring(bitcoinj.bitcoinSerialize());
}

代码示例来源:origin: Multibit-Legacy/multibit-hd

/**
 * Calculate the size of the transaction
 *
 * @param transaction The transaction to calculate the size of
 *
 * @return size of the transaction
 */
private int calculateSizeWithSignatures(Transaction transaction) throws IOException {
 ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
 transaction.bitcoinSerialize(byteOutputStream);
 int unsignedSize = byteOutputStream.size();
 // Add on size of signatures
 return unsignedSize + SIZE_OF_SIGNATURE * transaction.getInputs().size();
}

代码示例来源:origin: fr.acinq/bitcoinj-core

private void writeTransactions(OutputStream stream) throws IOException {
  // check for no transaction conditions first
  // must be a more efficient way to do this but I'm tired atm.
  if (transactions == null) {
    return;
  }
  // confirmed we must have transactions either cached or as objects.
  if (transactionBytesValid && payload != null && payload.length >= offset + length) {
    stream.write(payload, offset + HEADER_SIZE, length - HEADER_SIZE);
    return;
  }
  if (transactions != null) {
    stream.write(new VarInt(transactions.size()).encode());
    for (Transaction tx : transactions) {
      tx.bitcoinSerialize(stream);
    }
  }
}

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

private void writeTransactions(OutputStream stream) throws IOException {
  // check for no transaction conditions first
  // must be a more efficient way to do this but I'm tired atm.
  if (transactions == null) {
    return;
  }
  // confirmed we must have transactions either cached or as objects.
  if (transactionBytesValid && payload != null && payload.length >= offset + length) {
    stream.write(payload, offset + HEADER_SIZE, length - HEADER_SIZE);
    return;
  }
  if (transactions != null) {
    stream.write(new VarInt(transactions.size()).encode());
    for (Transaction tx : transactions) {
      tx.bitcoinSerialize(stream);
    }
  }
}

代码示例来源:origin: blockchain/thunder

public LNEstablishAMessage (ECKey channelKeyServer, Transaction anchor, RevocationHash revocationHash, long clientAmount, long
    serverAmount, int minConfirmationAnchor, Address address, int feePerByte, long csvDelay) {
  this.channelKeyServer = channelKeyServer.getPubKey();
  this.minConfirmationAnchor = minConfirmationAnchor;
  this.anchorTransaction = anchor.bitcoinSerialize();
  this.revocationHash = revocationHash;
  this.amountClient = clientAmount;
  this.amountServer = serverAmount;
  this.addressBytes = address.getHash160();
  this.feePerByte = feePerByte;
  this.csvDelay = csvDelay;
}

代码示例来源:origin: greenaddress/GreenBits

private void writeTransactions(OutputStream stream) throws IOException {
  // check for no transaction conditions first
  // must be a more efficient way to do this but I'm tired atm.
  if (transactions == null) {
    return;
  }
  // confirmed we must have transactions either cached or as objects.
  if (transactionBytesValid && payload != null && payload.length >= offset + length) {
    stream.write(payload, offset + HEADER_SIZE, length - HEADER_SIZE);
    return;
  }
  if (transactions != null) {
    stream.write(new VarInt(transactions.size()).encode());
    for (Transaction tx : transactions) {
      tx.bitcoinSerialize(stream);
    }
  }
}

代码示例来源:origin: HashEngineering/dashj

private void writeTransactions(OutputStream stream) throws IOException {
  // check for no transaction conditions first
  // must be a more efficient way to do this but I'm tired atm.
  if (transactions == null) {
    return;
  }
  // confirmed we must have transactions either cached or as objects.
  if (transactionBytesValid && payload != null && payload.length >= offset + length) {
    stream.write(payload, offset + HEADER_SIZE, length - HEADER_SIZE);
    return;
  }
  if (transactions != null) {
    stream.write(new VarInt(transactions.size()).encode());
    for (Transaction tx : transactions) {
      tx.bitcoinSerialize(stream);
    }
  }
  //writeMasterNodeVotes(stream);
}
/**

代码示例来源:origin: blockchain/unused-My-Wallet-V3-jar

public static synchronized Call<ResponseBody> publishTransaction(Transaction transaction, String apiCode)
    throws IOException {

    log.info("Publishing transaction");
    PushTx pushTx = new PushTx(BlockchainFramework.getRetrofitExplorerInstance(), apiCode);
    return pushTx.pushTx(new String(Hex.encode(transaction.bitcoinSerialize())));
  }
}

代码示例来源:origin: fr.acinq/bitcoinj-core

private static void sendTransactionsToListener(StoredBlock block, NewBlockType blockType,
                        TransactionReceivedInBlockListener listener,
                        int relativityOffset,
                        List<Transaction> transactions,
                        boolean clone,
                        Set<Sha256Hash> falsePositives) throws VerificationException {
  for (Transaction tx : transactions) {
    try {
      falsePositives.remove(tx.getHash());
      if (clone)
        tx = tx.params.getDefaultSerializer().makeTransaction(tx.bitcoinSerialize());
      listener.receiveFromBlock(tx, block, blockType, relativityOffset++);
    } catch (ScriptException e) {
      // We don't want scripts we don't understand to break the block chain so just note that this tx was
      // not scanned here and continue.
      log.warn("Failed to parse a script: " + e.toString());
    } catch (ProtocolException e) {
      // Failed to duplicate tx, should never happen.
      throw new RuntimeException(e);
    }
  }
}

代码示例来源:origin: HashEngineering/dashj

private static void sendTransactionsToListener(StoredBlock block, NewBlockType blockType,
                        TransactionReceivedInBlockListener listener,
                        int relativityOffset,
                        List<Transaction> transactions,
                        boolean clone,
                        Set<Sha256Hash> falsePositives) throws VerificationException {
  for (Transaction tx : transactions) {
    try {
      falsePositives.remove(tx.getHash());
      if (clone)
        tx = tx.params.getDefaultSerializer().makeTransaction(tx.bitcoinSerialize());
      listener.receiveFromBlock(tx, block, blockType, relativityOffset++);
    } catch (ScriptException e) {
      // We don't want scripts we don't understand to break the block chain so just note that this tx was
      // not scanned here and continue.
      log.warn("Failed to parse a script: " + e.toString());
    } catch (ProtocolException e) {
      // Failed to duplicate tx, should never happen.
      throw new RuntimeException(e);
    }
  }
}

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

private static void sendTransactionsToListener(StoredBlock block, NewBlockType blockType,
                        TransactionReceivedInBlockListener listener,
                        int relativityOffset,
                        List<Transaction> transactions,
                        boolean clone,
                        Set<Sha256Hash> falsePositives) throws VerificationException {
  for (Transaction tx : transactions) {
    try {
      falsePositives.remove(tx.getHash());
      if (clone)
        tx = tx.params.getDefaultSerializer().makeTransaction(tx.bitcoinSerialize());
      listener.receiveFromBlock(tx, block, blockType, relativityOffset++);
    } catch (ScriptException e) {
      // We don't want scripts we don't understand to break the block chain so just note that this tx was
      // not scanned here and continue.
      log.warn("Failed to parse a script: " + e.toString());
    } catch (ProtocolException e) {
      // Failed to duplicate tx, should never happen.
      throw new RuntimeException(e);
    }
  }
}

代码示例来源:origin: dogecoin/libdohj

@Override
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException {
  transaction.bitcoinSerialize(stream);
  stream.write(Utils.reverseBytes(hashBlock.getBytes()));
  coinbaseBranch.bitcoinSerialize(stream);
  chainMerkleBranch.bitcoinSerialize(stream);
  parentBlockHeader.bitcoinSerializeToStream(stream);
}

代码示例来源:origin: DanielKrawisz/Shufflepuff

public String sendOffline(String destinationAddress, long amountSatoshis) throws InsufficientMoneyException {
 Address addressj;
 try {
   addressj = new Address(params, destinationAddress);
 } catch (AddressFormatException e) {
   e.printStackTrace();
   throw new RuntimeException(e);
 }
 Coin amount = Coin.valueOf(amountSatoshis);
 // create a SendRequest of amount to destinationAddress
 Wallet.SendRequest sendRequest = Wallet.SendRequest.to(addressj, amount);
 // set dynamic fee
 sendRequest.feePerKb = getRecommendedFee();
 // complete & sign tx
 kit.wallet().completeTx(sendRequest);
 kit.wallet().signTransaction(sendRequest);
 // return tx bytes as hex encoded String
 return Hex.encodeHexString(sendRequest.tx.bitcoinSerialize());
}

代码示例来源:origin: greenaddress/GreenBits

@Test
public void pinHandlers() throws Exception {
  Transaction tx = PARAMS.getDefaultSerializer().makeTransaction(tx1.bitcoinSerialize());
  Sha256Hash hash = tx.getHash();
  table.seen(hash, address1);
  assertEquals(1, tx.getConfidence().numBroadcastPeers());
  final int[] seen = new int[1];
  tx.getConfidence().addEventListener(Threading.SAME_THREAD, new TransactionConfidence.Listener() {
    @Override
    public void onConfidenceChanged(TransactionConfidence confidence, ChangeReason reason) {
      seen[0] = confidence.numBroadcastPeers();
    }
  });
  tx = null;
  System.gc();
  table.seen(hash, address2);
  assertEquals(2, seen[0]);
}

代码示例来源:origin: greenaddress/GreenBits

@Test
public void balances() throws Exception {
  Coin nanos = COIN;
  Transaction tx1 = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, nanos);
  assertEquals(nanos, tx1.getValueSentToMe(wallet));
  assertTrue(tx1.getWalletOutputs(wallet).size() >= 1);
  // Send 0.10 to somebody else.
  Transaction send1 = wallet.createSend(OTHER_ADDRESS, valueOf(0, 10));
  // Reserialize.
  Transaction send2 = PARAMS.getDefaultSerializer().makeTransaction(send1.bitcoinSerialize());
  assertEquals(nanos, send2.getValueSentFromMe(wallet));
  assertEquals(ZERO.subtract(valueOf(0, 10)), send2.getValue(wallet));
}

代码示例来源:origin: greenaddress/GreenBits

@Test
public void isConsistent_duplicates() throws Exception {
  // This test ensures that isConsistent catches duplicate transactions, eg, because we submitted the same block
  // twice (this is not allowed).
  Transaction tx = createFakeTx(PARAMS, COIN, myAddress);
  TransactionOutput output = new TransactionOutput(PARAMS, tx, valueOf(0, 5), OTHER_ADDRESS);
  tx.addOutput(output);
  wallet.receiveFromBlock(tx, null, BlockChain.NewBlockType.BEST_CHAIN, 0);
  assertTrue(wallet.isConsistent());
  Transaction txClone = PARAMS.getDefaultSerializer().makeTransaction(tx.bitcoinSerialize());
  try {
    wallet.receiveFromBlock(txClone, null, BlockChain.NewBlockType.BEST_CHAIN, 0);
    fail("Illegal argument not thrown when it should have been.");
  } catch (IllegalStateException ex) {
    // expected
  }
}

相关文章

微信公众号

最新文章

更多

Transaction类方法