当前位置: 首页>>代码示例>>Java>>正文


Java CloseReason.TIME_WINDOW_TOO_LARGE属性代码示例

本文整理汇总了Java中com.google.bitcoin.protocols.channels.PaymentChannelCloseException.CloseReason.TIME_WINDOW_TOO_LARGE属性的典型用法代码示例。如果您正苦于以下问题:Java CloseReason.TIME_WINDOW_TOO_LARGE属性的具体用法?Java CloseReason.TIME_WINDOW_TOO_LARGE怎么用?Java CloseReason.TIME_WINDOW_TOO_LARGE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.google.bitcoin.protocols.channels.PaymentChannelCloseException.CloseReason的用法示例。


在下文中一共展示了CloseReason.TIME_WINDOW_TOO_LARGE属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: receiveInitiate

@Nullable
@GuardedBy("lock")
private CloseReason receiveInitiate(Protos.Initiate initiate, BigInteger contractValue, Protos.Error.Builder errorBuilder) throws VerificationException, InsufficientMoneyException {
    log.info("Got INITIATE message:\n{}", initiate.toString());

    checkState(initiate.getExpireTimeSecs() > 0 && initiate.getMinAcceptedChannelSize() >= 0);

    final long MAX_EXPIRY_TIME = Utils.currentTimeMillis() / 1000 + MAX_TIME_WINDOW;
    if (initiate.getExpireTimeSecs() > MAX_EXPIRY_TIME) {
        log.error("Server expiry time was out of our allowed bounds: {} vs {}", initiate.getExpireTimeSecs(),
                MAX_EXPIRY_TIME);
        errorBuilder.setCode(Protos.Error.ErrorCode.TIME_WINDOW_TOO_LARGE);
        errorBuilder.setExpectedValue(MAX_EXPIRY_TIME);
        return CloseReason.TIME_WINDOW_TOO_LARGE;
    }

    BigInteger minChannelSize = BigInteger.valueOf(initiate.getMinAcceptedChannelSize());
    if (contractValue.compareTo(minChannelSize) < 0) {
        log.error("Server requested too much value");
        errorBuilder.setCode(Protos.Error.ErrorCode.CHANNEL_VALUE_TOO_LARGE);
        missing = minChannelSize.subtract(contractValue);
        return CloseReason.SERVER_REQUESTED_TOO_MUCH_VALUE;
    }

    // For now we require a hard-coded value. In future this will have to get more complex and dynamic as the fees
    // start to float.
    final long MIN_PAYMENT = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.longValue();
    if (initiate.getMinPayment() != MIN_PAYMENT) {
        log.error("Server requested a min payment of {} but we expected {}", initiate.getMinPayment(), MIN_PAYMENT);
        errorBuilder.setCode(Protos.Error.ErrorCode.MIN_PAYMENT_TOO_LARGE);
        errorBuilder.setExpectedValue(MIN_PAYMENT);
        missing = BigInteger.valueOf(initiate.getMinPayment() - MIN_PAYMENT);
        return CloseReason.SERVER_REQUESTED_TOO_MUCH_VALUE;
    }

    state = new PaymentChannelClientState(wallet, myKey,
            new ECKey(null, initiate.getMultisigKey().toByteArray()),
            contractValue, initiate.getExpireTimeSecs());
    try {
        state.initiate();
    } catch (ValueOutOfRangeException e) {
        log.error("Value out of range when trying to initiate", e);
        errorBuilder.setCode(Protos.Error.ErrorCode.CHANNEL_VALUE_TOO_LARGE);
        return CloseReason.SERVER_REQUESTED_TOO_MUCH_VALUE;
    }
    minPayment = initiate.getMinPayment();
    step = InitStep.WAITING_FOR_REFUND_RETURN;

    Protos.ProvideRefund.Builder provideRefundBuilder = Protos.ProvideRefund.newBuilder()
            .setMultisigKey(ByteString.copyFrom(myKey.getPubKey()))
            .setTx(ByteString.copyFrom(state.getIncompleteRefundTransaction().bitcoinSerialize()));

    conn.sendToServer(Protos.TwoWayChannelMessage.newBuilder()
            .setProvideRefund(provideRefundBuilder)
            .setType(Protos.TwoWayChannelMessage.MessageType.PROVIDE_REFUND)
            .build());
    return null;
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:58,代码来源:PaymentChannelClient.java

示例2: receiveInitiate

@Nullable
@GuardedBy("lock")
private CloseReason receiveInitiate(Protos.Initiate initiate, BigInteger contractValue, Protos.Error.Builder errorBuilder) throws VerificationException, InsufficientMoneyException {
    log.info("Got INITIATE message:\n{}", initiate.toString());

    checkState(initiate.getExpireTimeSecs() > 0 && initiate.getMinAcceptedChannelSize() >= 0);

    final long MAX_EXPIRY_TIME = Utils.currentTimeSeconds() + MAX_TIME_WINDOW;
    if (initiate.getExpireTimeSecs() > MAX_EXPIRY_TIME) {
        log.error("Server expiry time was out of our allowed bounds: {} vs {}", initiate.getExpireTimeSecs(),
                MAX_EXPIRY_TIME);
        errorBuilder.setCode(Protos.Error.ErrorCode.TIME_WINDOW_TOO_LARGE);
        errorBuilder.setExpectedValue(MAX_EXPIRY_TIME);
        return CloseReason.TIME_WINDOW_TOO_LARGE;
    }

    BigInteger minChannelSize = BigInteger.valueOf(initiate.getMinAcceptedChannelSize());
    if (contractValue.compareTo(minChannelSize) < 0) {
        log.error("Server requested too much value");
        errorBuilder.setCode(Protos.Error.ErrorCode.CHANNEL_VALUE_TOO_LARGE);
        missing = minChannelSize.subtract(contractValue);
        return CloseReason.SERVER_REQUESTED_TOO_MUCH_VALUE;
    }

    // For now we require a hard-coded value. In future this will have to get more complex and dynamic as the fees
    // start to float.
    final long MIN_PAYMENT = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.longValue();
    if (initiate.getMinPayment() != MIN_PAYMENT) {
        log.error("Server requested a min payment of {} but we expected {}", initiate.getMinPayment(), MIN_PAYMENT);
        errorBuilder.setCode(Protos.Error.ErrorCode.MIN_PAYMENT_TOO_LARGE);
        errorBuilder.setExpectedValue(MIN_PAYMENT);
        missing = BigInteger.valueOf(initiate.getMinPayment() - MIN_PAYMENT);
        return CloseReason.SERVER_REQUESTED_TOO_MUCH_VALUE;
    }

    state = new PaymentChannelClientState(wallet, myKey,
            new ECKey(null, initiate.getMultisigKey().toByteArray()),
            contractValue, initiate.getExpireTimeSecs());
    try {
        state.initiate();
    } catch (ValueOutOfRangeException e) {
        log.error("Value out of range when trying to initiate", e);
        errorBuilder.setCode(Protos.Error.ErrorCode.CHANNEL_VALUE_TOO_LARGE);
        return CloseReason.SERVER_REQUESTED_TOO_MUCH_VALUE;
    }
    minPayment = initiate.getMinPayment();
    step = InitStep.WAITING_FOR_REFUND_RETURN;

    Protos.ProvideRefund.Builder provideRefundBuilder = Protos.ProvideRefund.newBuilder()
            .setMultisigKey(ByteString.copyFrom(myKey.getPubKey()))
            .setTx(ByteString.copyFrom(state.getIncompleteRefundTransaction().bitcoinSerialize()));

    conn.sendToServer(Protos.TwoWayChannelMessage.newBuilder()
            .setProvideRefund(provideRefundBuilder)
            .setType(Protos.TwoWayChannelMessage.MessageType.PROVIDE_REFUND)
            .build());
    return null;
}
 
开发者ID:HashEngineering,项目名称:quarkcoinj,代码行数:58,代码来源:PaymentChannelClient.java

示例3: receiveInitiate

@Nullable
@GuardedBy("lock")
private CloseReason receiveInitiate(Protos.Initiate initiate, BigInteger contractValue, Protos.Error.Builder errorBuilder) throws VerificationException, InsufficientMoneyException {
    log.info("Got INITIATE message:\n{}", initiate.toString());

    checkState(initiate.getExpireTimeSecs() > 0 && initiate.getMinAcceptedChannelSize() >= 0);

    final long MAX_EXPIRY_TIME = Utils.now().getTime() / 1000 + MAX_TIME_WINDOW;
    if (initiate.getExpireTimeSecs() > MAX_EXPIRY_TIME) {
        log.error("Server expiry time was out of our allowed bounds: {} vs {}", initiate.getExpireTimeSecs(),
                MAX_EXPIRY_TIME);
        errorBuilder.setCode(Protos.Error.ErrorCode.TIME_WINDOW_TOO_LARGE);
        errorBuilder.setExpectedValue(MAX_EXPIRY_TIME);
        return CloseReason.TIME_WINDOW_TOO_LARGE;
    }

    BigInteger minChannelSize = BigInteger.valueOf(initiate.getMinAcceptedChannelSize());
    if (maxValue.compareTo(minChannelSize) < 0) {
        log.error("Server requested too much value");
        errorBuilder.setCode(Protos.Error.ErrorCode.CHANNEL_VALUE_TOO_LARGE);
        return CloseReason.SERVER_REQUESTED_TOO_MUCH_VALUE;
    }

    // For now we require a hard-coded value. In future this will have to get more complex and dynamic as the fees
    // start to float.
    final long MIN_PAYMENT = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.longValue();
    if (initiate.getMinPayment() != MIN_PAYMENT) {
        log.error("Server requested a min payment of {} but we expected {}", initiate.getMinPayment(), MIN_PAYMENT);
        errorBuilder.setCode(Protos.Error.ErrorCode.MIN_PAYMENT_TOO_LARGE);
        errorBuilder.setExpectedValue(MIN_PAYMENT);
        return CloseReason.SERVER_REQUESTED_TOO_MUCH_VALUE;
    }

    state = new PaymentChannelClientState(wallet, myKey,
            new ECKey(null, initiate.getMultisigKey().toByteArray()),
            contractValue, initiate.getExpireTimeSecs());
    try {
        state.initiate();
    } catch (ValueOutOfRangeException e) {
        log.error("Value out of range when trying to initiate", e);
        errorBuilder.setCode(Protos.Error.ErrorCode.CHANNEL_VALUE_TOO_LARGE);
        return CloseReason.SERVER_REQUESTED_TOO_MUCH_VALUE;
    }
    minPayment = initiate.getMinPayment();
    step = InitStep.WAITING_FOR_REFUND_RETURN;

    Protos.ProvideRefund.Builder provideRefundBuilder = Protos.ProvideRefund.newBuilder()
            .setMultisigKey(ByteString.copyFrom(myKey.getPubKey()))
            .setTx(ByteString.copyFrom(state.getIncompleteRefundTransaction().bitcoinSerialize()));

    conn.sendToServer(Protos.TwoWayChannelMessage.newBuilder()
            .setProvideRefund(provideRefundBuilder)
            .setType(Protos.TwoWayChannelMessage.MessageType.PROVIDE_REFUND)
            .build());
    return null;
}
 
开发者ID:9cat,项目名称:templecoin-java,代码行数:56,代码来源:PaymentChannelClient.java


注:本文中的com.google.bitcoin.protocols.channels.PaymentChannelCloseException.CloseReason.TIME_WINDOW_TOO_LARGE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。