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

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

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

Transaction.getMessageSize介绍

[英]The priority (coin age) calculation doesn't use the regular message size, but rather one adjusted downwards for the number of inputs. The goal is to incentivise cleaning up the UTXO set with free transactions, if one can do so.
[中]优先级(硬币年龄)计算不使用常规消息大小,而是根据输入数量向下调整。其目标是激励人们用自由交易清理UTXO集合,如果可以的话。

代码示例

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

public int getOptimalEncodingMessageSize() {
  if (optimalEncodingMessageSize != 0)
    return optimalEncodingMessageSize;
  optimalEncodingMessageSize = getMessageSize();
  return optimalEncodingMessageSize;
}

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

@Test
public void testPrioSizeCalc() throws Exception {
  Transaction tx1 = FakeTxBuilder.createFakeTx(PARAMS, Coin.COIN, ADDRESS);
  int size1 = tx1.getMessageSize();
  int size2 = tx1.getMessageSizeForPriorityCalc();
  assertEquals(113, size1 - size2);
  tx1.getInput(0).setScriptSig(new Script(new byte[109]));
  assertEquals(78, tx1.getMessageSizeForPriorityCalc());
  tx1.getInput(0).setScriptSig(new Script(new byte[110]));
  assertEquals(78, tx1.getMessageSizeForPriorityCalc());
  tx1.getInput(0).setScriptSig(new Script(new byte[111]));
  assertEquals(79, tx1.getMessageSizeForPriorityCalc());
}

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

public int getOptimalEncodingMessageSize() {
  if (optimalEncodingMessageSize != 0)
    return optimalEncodingMessageSize;
  optimalEncodingMessageSize = getMessageSize();
  return optimalEncodingMessageSize;
}

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

public int getOptimalEncodingMessageSize() {
  if (optimalEncodingMessageSize != 0)
    return optimalEncodingMessageSize;
  optimalEncodingMessageSize = getMessageSize();
  return optimalEncodingMessageSize;
}

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

public int getOptimalEncodingMessageSize() {
  if (optimalEncodingMessageSize != 0)
    return optimalEncodingMessageSize;
  optimalEncodingMessageSize = getMessageSize();
  return optimalEncodingMessageSize;
}

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

private int countAndMeasureSize(Collection<Transaction> transactions) {
  for (Transaction transaction : transactions)
    bytesInLastSecond += transaction.getMessageSize();
  return transactions.size();
}

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

private int countAndMeasureSize(Collection<Transaction> transactions) {
  for (Transaction transaction : transactions)
    bytesInLastSecond += transaction.getMessageSize();
  return transactions.size();
}

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

private int countAndMeasureSize(Collection<Transaction> transactions) {
  for (Transaction transaction : transactions)
    bytesInLastSecond += transaction.getMessageSize();
  return transactions.size();
}

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

private int countAndMeasureSize(Collection<Transaction> transactions) {
  for (Transaction transaction : transactions)
    bytesInLastSecond += transaction.getMessageSize();
  return transactions.size();
}

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

/**
 * The priority (coin age) calculation doesn't use the regular message size, but rather one adjusted downwards
 * for the number of inputs. The goal is to incentivise cleaning up the UTXO set with free transactions, if one
 * can do so.
 */
public int getMessageSizeForPriorityCalc() {
  int size = getMessageSize();
  for (TransactionInput input : inputs) {
    // 41: min size of an input
    // 110: enough to cover a compressed pubkey p2sh redemption (somewhat arbitrary).
    int benefit = 41 + Math.min(110, input.getScriptSig().getProgram().length);
    if (size > benefit)
      size -= benefit;
  }
  return size;
}

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

/**
 * The priority (coin age) calculation doesn't use the regular message size, but rather one adjusted downwards
 * for the number of inputs. The goal is to incentivise cleaning up the UTXO set with free transactions, if one
 * can do so.
 */
public int getMessageSizeForPriorityCalc() {
  int size = getMessageSize();
  for (TransactionInput input : inputs) {
    // 41: min size of an input
    // 110: enough to cover a compressed pubkey p2sh redemption (somewhat arbitrary).
    int benefit = 41 + Math.min(110, input.getScriptSig().getProgram().length);
    if (size > benefit)
      size -= benefit;
  }
  return size;
}

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

/**
 * The priority (coin age) calculation doesn't use the regular message size, but rather one adjusted downwards
 * for the number of inputs. The goal is to incentivise cleaning up the UTXO set with free transactions, if one
 * can do so.
 */
public int getMessageSizeForPriorityCalc() {
  int size = getMessageSize();
  for (TransactionInput input : inputs) {
    // 41: min size of an input
    // 110: enough to cover a compressed pubkey p2sh redemption (somewhat arbitrary).
    int benefit = 41 + Math.min(110, input.getScriptSig().getProgram().length);
    if (size > benefit)
      size -= benefit;
  }
  return size;
}

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

/**
 * The priority (coin age) calculation doesn't use the regular message size, but rather one adjusted downwards
 * for the number of inputs. The goal is to incentivise cleaning up the UTXO set with free transactions, if one
 * can do so.
 */
public int getMessageSizeForPriorityCalc() {
  int size = getMessageSize();
  for (TransactionInput input : inputs) {
    // 41: min size of an input
    // 110: enough to cover a compressed pubkey p2sh redemption (somewhat arbitrary).
    int benefit = 41 + Math.min(110, input.getScriptSig().getProgram().length);
    if (size > benefit)
      size -= benefit;
  }
  return size;
}

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

Transaction tx = new Transaction(params, transactions, offset);
transactionList.add(tx);
offset += tx.getMessageSize();

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

/**
 * Parse transactions from the block.
 * 
 * @param transactionsOffset Offset of the transactions within the block.
 * Useful for non-Bitcoin chains where the block header may not be a fixed
 * size.
 */
protected void parseTransactions(final int transactionsOffset) throws ProtocolException {
  cursor = transactionsOffset;
  optimalEncodingMessageSize = HEADER_SIZE;
  if (payload.length == cursor) {
    // This message is just a header, it has no transactions.
    transactionBytesValid = false;
    return;
  }
  int numTransactions = (int) readVarInt();
  optimalEncodingMessageSize += VarInt.sizeOf(numTransactions);
  transactions = new ArrayList<>(numTransactions);
  for (int i = 0; i < numTransactions; i++) {
    Transaction tx = new Transaction(params, payload, cursor, this, serializer, UNKNOWN_LENGTH);
    // Label the transaction as coming from the P2P network, so code that cares where we first saw it knows.
    tx.getConfidence().setSource(TransactionConfidence.Source.NETWORK);
    transactions.add(tx);
    cursor += tx.getMessageSize();
    optimalEncodingMessageSize += tx.getOptimalEncodingMessageSize();
  }
  transactionBytesValid = serializer.isParseRetainMode();
}

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

/**
 * Parse transactions from the block.
 * 
 * @param transactionsOffset Offset of the transactions within the block.
 * Useful for non-Bitcoin chains where the block header may not be a fixed
 * size.
 */
protected void parseTransactions(final int transactionsOffset) throws ProtocolException {
  cursor = transactionsOffset;
  optimalEncodingMessageSize = HEADER_SIZE;
  if (payload.length == cursor) {
    // This message is just a header, it has no transactions.
    transactionBytesValid = false;
    return;
  }
  int numTransactions = (int) readVarInt();
  optimalEncodingMessageSize += VarInt.sizeOf(numTransactions);
  transactions = new ArrayList<>(numTransactions);
  for (int i = 0; i < numTransactions; i++) {
    Transaction tx = new Transaction(params, payload, cursor, this, serializer, UNKNOWN_LENGTH);
    // Label the transaction as coming from the P2P network, so code that cares where we first saw it knows.
    tx.getConfidence().setSource(TransactionConfidence.Source.NETWORK);
    transactions.add(tx);
    cursor += tx.getMessageSize();
    optimalEncodingMessageSize += tx.getOptimalEncodingMessageSize();
  }
  transactionBytesValid = serializer.isParseRetainMode();
}

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

/**
 * Parse transactions from the block.
 * 
 * @param transactionsOffset Offset of the transactions within the block.
 * Useful for non-Bitcoin chains where the block header may not be a fixed
 * size.
 */
protected void parseTransactions(final int transactionsOffset) throws ProtocolException {
  cursor = transactionsOffset;
  optimalEncodingMessageSize = HEADER_SIZE;
  if (payload.length == cursor) {
    // This message is just a header, it has no transactions.
    transactionBytesValid = false;
    return;
  }
  int numTransactions = (int) readVarInt();
  optimalEncodingMessageSize += VarInt.sizeOf(numTransactions);
  transactions = new ArrayList<Transaction>(numTransactions);
  for (int i = 0; i < numTransactions; i++) {
    Transaction tx = new Transaction(params, payload, cursor, this, serializer, UNKNOWN_LENGTH);
    // Label the transaction as coming from the P2P network, so code that cares where we first saw it knows.
    tx.getConfidence().setSource(TransactionConfidence.Source.NETWORK);
    transactions.add(tx);
    cursor += tx.getMessageSize();
    optimalEncodingMessageSize += tx.getOptimalEncodingMessageSize();
  }
  transactionBytesValid = serializer.isParseRetainMode();
}

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

/**
 * Parse transactions from the block.
 * 
 * @param transactionsOffset Offset of the transactions within the block.
 * Useful for non-Bitcoin chains where the block header may not be a fixed
 * size.
 */
protected void parseTransactions(final int transactionsOffset) throws ProtocolException {
  cursor = transactionsOffset;
  optimalEncodingMessageSize = HEADER_SIZE;
  if (payload.length == cursor) {
    // This message is just a header, it has no transactions.
    transactionBytesValid = false;
    return;
  }
  int numTransactions = (int) readVarInt();
  optimalEncodingMessageSize += VarInt.sizeOf(numTransactions);
  transactions = new ArrayList<Transaction>(numTransactions);
  for (int i = 0; i < numTransactions; i++) {
    Transaction tx = new Transaction(params, payload, cursor, this, serializer, UNKNOWN_LENGTH);
    // Label the transaction as coming from the P2P network, so code that cares where we first saw it knows.
    tx.getConfidence().setSource(TransactionConfidence.Source.NETWORK);
    transactions.add(tx);
    cursor += tx.getMessageSize();
    optimalEncodingMessageSize += tx.getOptimalEncodingMessageSize();
  }
  transactionBytesValid = serializer.isParseRetainMode();
}

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

if (inputs.size() == 0 || outputs.size() == 0)
  throw new VerificationException.EmptyInputsOrOutputs();
if (this.getMessageSize() > Block.MAX_BLOCK_SIZE)
  throw new VerificationException.LargerThanMaxBlockSize();

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

@Override
public Transaction getChannelTransaction (TransactionOutPoint anchor, ChannelStatus channelStatus, ECKey client, ECKey server) {
  Transaction transaction = new Transaction(Constants.getNetwork());
  transaction.addInput(anchor.getHash(), anchor.getIndex(), Tools.getDummyScript());
  transaction.addOutput(Coin.valueOf(0), ScriptTools.getChannelTxOutputRevocation(channelStatus.revocationHashClient,
      client, server, Constants.ESCAPE_REVOCATION_TIME));
  transaction.addOutput(Coin.valueOf(0), channelStatus.addressServer);
  transaction = addPayments(transaction, channelStatus, channelStatus.revocationHashClient, client, server);
  //Missing two signatures, max 146B
  long fee = (long) Math.ceil((transaction.getMessageSize() + 146) * channelStatus.feePerByte / 2);
  transaction.getOutput(0).setValue(Coin.valueOf(channelStatus.amountClient - fee));
  transaction.getOutput(1).setValue(Coin.valueOf(channelStatus.amountServer - fee));
  return transaction;
}

相关文章

微信公众号

最新文章

更多

Transaction类方法