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

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

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

Transaction.toString介绍

[英]A human readable version of the transaction useful for debugging. The format is not guaranteed to be stable.
[中]用于调试的事务的可读版本。格式不能保证稳定。

代码示例

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

@Override
public String toString() {
  return toString(null);
}

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

@Override
public String toString() {
  return toString(null);
}

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

@Override
public String toString() {
  return toString(null);
}

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

@Override
public String toString() {
  return toString(null);
}

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

/**
 * Creates a transaction by reading payload starting from offset bytes in. Length of a transaction is fixed.
 */
/*public TransactionLockRequest(NetworkParameters params, byte[] payload, @Nullable Message parent, boolean parseLazy, boolean parseRetain, int length)
    throws ProtocolException {
  super(params, payload, 0, parent, parseLazy, parseRetain, length);
}*/
public String toString(@Nullable AbstractBlockChain chain) {
  return "Transaction Lock Request:\n" + super.toString(chain);
}

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

/**
 * 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(@Nullable AbstractBlockChain chain) {
  return transaction.toString(chain);
}

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

@Override
  public String toString() {
    final String newline = String.format(Locale.US, "%n");
    final String closeStr = close == null ? "still open" : close.toString().replaceAll(newline, newline + "   ");
    return String.format(Locale.US, "Stored client channel for server ID %s (%s)%n" +
        "    Version:     %d%n" +
        "    Key:         %s%n" +
        "    Server key:  %s%n" +
        "    Value left:  %s%n" +
        "    Refund fees: %s%n" +
        "    Expiry     : %s%n" +
        "    Contract:  %s" +
        "Refund:    %s" +
        "Close:     %s",
        id, active ? "active" : "inactive", majorVersion, myKey, serverKey, valueToMe, refundFees, expiryTime,
        contract.toString().replaceAll(newline, newline + "    "),
        refund.toString().replaceAll(newline, newline + "    "),
        closeStr);
  }
}

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

@Override
  public String toString() {
    final String newline = String.format(Locale.US, "%n");
    final String closeStr = close == null ? "still open" : close.toString().replaceAll(newline, newline + "   ");
    return String.format(Locale.US, "Stored client channel for server ID %s (%s)%n" +
        "    Version:     %d%n" +
        "    Key:         %s%n" +
        "    Server key:  %s%n" +
        "    Value left:  %s%n" +
        "    Refund fees: %s%n" +
        "    Expiry     : %s%n" +
        "    Contract:  %s" +
        "Refund:    %s" +
        "Close:     %s",
        id, active ? "active" : "inactive", majorVersion, myKey, serverKey, valueToMe, refundFees, expiryTime,
        contract.toString().replaceAll(newline, newline + "    "),
        refund.toString().replaceAll(newline, newline + "    "),
        closeStr);
  }
}

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

@Override
  public synchronized String toString() {
    final String newline = String.format(Locale.US, "%n");
    return String.format(Locale.US, "Stored server channel (%s)%n" +
        "    Version:       %d%n" +
        "    Key:           %s%n" +
        "    Value to me:   %s%n" +
        "    Client output: %s%n" +
        "    Refund unlock: %s (%d unix time)%n" +
        "    Contract:    %s%n",
        connectedHandler != null ? "connected" : "disconnected", majorVersion, myKey, bestValueToMe,
        clientOutput,  new Date(refundTransactionUnlockTimeSecs * 1000), refundTransactionUnlockTimeSecs,
        contract.toString().replaceAll(newline, newline + "    "));
  }
}

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

@Override
  public synchronized String toString() {
    final String newline = String.format(Locale.US, "%n");
    return String.format(Locale.US, "Stored server channel (%s)%n" +
        "    Version:       %d%n" +
        "    Key:           %s%n" +
        "    Value to me:   %s%n" +
        "    Client output: %s%n" +
        "    Refund unlock: %s (%d unix time)%n" +
        "    Contract:    %s%n",
        connectedHandler != null ? "connected" : "disconnected", majorVersion, myKey, bestValueToMe,
        clientOutput,  new Date(refundTransactionUnlockTimeSecs * 1000), refundTransactionUnlockTimeSecs,
        contract.toString().replaceAll(newline, newline + "    "));
  }
}

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

@Override
  public String toString() {
    final String newline = String.format(Locale.US, "%n");
    final String closeStr = close == null ? "still open" : close.toString().replaceAll(newline, newline + "   ");
    return String.format(Locale.US, "Stored client channel for server ID %s (%s)%n" +
        "    Version:     %d%n" +
        "    Key:         %s%n" +
        "    Server key:  %s%n" +
        "    Value left:  %s%n" +
        "    Refund fees: %s%n" +
        "    Expiry     : %s%n" +
        "    Contract:  %s" +
        "Refund:    %s" +
        "Close:     %s",
        id, active ? "active" : "inactive", majorVersion, myKey, serverKey, valueToMe, refundFees, expiryTime,
        contract.toString().replaceAll(newline, newline + "    "),
        refund.toString().replaceAll(newline, newline + "    "),
        closeStr);
  }
}

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

@Override
  public synchronized String toString() {
    final String newline = String.format(Locale.US, "%n");
    return String.format(Locale.US, "Stored server channel (%s)%n" +
        "    Version:       %d%n" +
        "    Key:           %s%n" +
        "    Value to me:   %s%n" +
        "    Client output: %s%n" +
        "    Refund unlock: %s (%d unix time)%n" +
        "    Contract:    %s%n",
        connectedHandler != null ? "connected" : "disconnected", majorVersion, myKey, bestValueToMe,
        clientOutput,  new Date(refundTransactionUnlockTimeSecs * 1000), refundTransactionUnlockTimeSecs,
        contract.toString().replaceAll(newline, newline + "    "));
  }
}

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

@Override
  public String toString() {
    final String newline = String.format(Locale.US, "%n");
    final String closeStr = close == null ? "still open" : close.toString().replaceAll(newline, newline + "   ");
    return String.format(Locale.US, "Stored client channel for server ID %s (%s)%n" +
        "    Version:     %d%n" +
        "    Key:         %s%n" +
        "    Server key:  %s%n" +
        "    Value left:  %s%n" +
        "    Refund fees: %s%n" +
        "    Expiry     : %s%n" +
        "    Contract:  %s" +
        "Refund:    %s" +
        "Close:     %s",
        id, active ? "active" : "inactive", majorVersion, myKey, serverKey, valueToMe, refundFees, expiryTime,
        contract.toString().replaceAll(newline, newline + "    "),
        refund.toString().replaceAll(newline, newline + "    "),
        closeStr);
  }
}

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

@Override
  public synchronized String toString() {
    final String newline = String.format(Locale.US, "%n");
    return String.format(Locale.US, "Stored server channel (%s)%n" +
        "    Version:       %d%n" +
        "    Key:           %s%n" +
        "    Value to me:   %s%n" +
        "    Client output: %s%n" +
        "    Refund unlock: %s (%d unix time)%n" +
        "    Contract:    %s%n",
        connectedHandler != null ? "connected" : "disconnected", majorVersion, myKey, bestValueToMe,
        clientOutput,  new Date(refundTransactionUnlockTimeSecs * 1000), refundTransactionUnlockTimeSecs,
        contract.toString().replaceAll(newline, newline + "    "));
  }
}

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

@Override
  public synchronized void onCoinsReceived(Wallet w, Transaction tx, Coin prevBalance, Coin newBalance) {
    System.out.println("\nReceived tx " + tx.getHashAsString());
    System.out.println(tx.toString());
  }
});

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

private void toStringHelper(StringBuilder builder, Map<Sha256Hash, Transaction> transactionMap,
              @Nullable AbstractBlockChain chain, @Nullable Comparator<Transaction> sortOrder) {
  checkState(lock.isHeldByCurrentThread());
  final Collection<Transaction> txns;
  if (sortOrder != null) {
    txns = new TreeSet<>(sortOrder);
    txns.addAll(transactionMap.values());
  } else {
    txns = transactionMap.values();
  }
  for (Transaction tx : txns) {
    try {
      builder.append(tx.getValue(this).toFriendlyString());
      builder.append(" total value (sends ");
      builder.append(tx.getValueSentFromMe(this).toFriendlyString());
      builder.append(" and receives ");
      builder.append(tx.getValueSentToMe(this).toFriendlyString());
      builder.append(")\n");
    } catch (ScriptException e) {
      // Ignore and don't print this line.
    }
    if (tx.hasConfidence())
      builder.append("  confidence: ").append(tx.getConfidence()).append('\n');
    builder.append(tx.toString(chain));
  }
}

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

@Test
public void testToStringWhenThereAreZeroInputs() {
  Transaction tx = new Transaction(PARAMS);
  assertEquals(tx.toString().contains("No inputs!"), true);
}

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

@Test
public void testToStringWhenLockTimeIsSpecifiedInBlockHeight() {
  Transaction tx = FakeTxBuilder.createFakeTx(PARAMS);
  TransactionInput input = tx.getInput(0);
  input.setSequenceNumber(42);
  int TEST_LOCK_TIME = 20;
  tx.setLockTime(TEST_LOCK_TIME);
  Calendar cal = Calendar.getInstance();
  cal.set(2085, 10, 4, 17, 53, 21);
  cal.set(Calendar.MILLISECOND, 0);
  BlockChain mockBlockChain = createMock(BlockChain.class);
  EasyMock.expect(mockBlockChain.estimateBlockTime(TEST_LOCK_TIME)).andReturn(cal.getTime());
  replay(mockBlockChain);
  String str = tx.toString(mockBlockChain);
  assertEquals(str.contains("block " + TEST_LOCK_TIME), true);
  assertEquals(str.contains("estimated to be reached at"), true);
}

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

@Test
public void testToStringWhenIteratingOverAnInputCatchesAnException() {
  Transaction tx = FakeTxBuilder.createFakeTx(PARAMS);
  TransactionInput ti = new TransactionInput(PARAMS, tx, new byte[0]) {
    @Override
    public Script getScriptSig() throws ScriptException {
      throw new ScriptException("");
    }
  };
  tx.addInput(ti);
  assertEquals(tx.toString().contains("[exception: "), true);
}

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

@Test
public void pubkeyOnlyScripts() throws Exception {
  // Verify that we support outputs like OP_PUBKEY and the corresponding inputs.
  ECKey key1 = wallet.freshReceiveKey();
  Coin value = valueOf(5, 0);
  Transaction t1 = createFakeTx(PARAMS, value, key1);
  if (wallet.isPendingTransactionRelevant(t1))
    wallet.receivePending(t1, null);
  // TX should have been seen as relevant.
  assertEquals(value, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
  assertEquals(ZERO, wallet.getBalance(Wallet.BalanceType.AVAILABLE));
  sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, t1);
  // TX should have been seen as relevant, extracted and processed.
  assertEquals(value, wallet.getBalance(Wallet.BalanceType.AVAILABLE));
  // Spend it and ensure we can spend the <key> OP_CHECKSIG output correctly.
  Transaction t2 = wallet.createSend(OTHER_ADDRESS, value);
  assertNotNull(t2);
  // TODO: This code is messy, improve the Script class and fixinate!
  assertEquals(t2.toString(), 1, t2.getInputs().get(0).getScriptSig().getChunks().size());
  assertTrue(t2.getInputs().get(0).getScriptSig().getChunks().get(0).data.length > 50);
}

相关文章

微信公众号

最新文章

更多

Transaction类方法