本文整理汇总了Java中org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason类的典型用法代码示例。如果您正苦于以下问题:Java CloseReason类的具体用法?Java CloseReason怎么用?Java CloseReason使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CloseReason类属于org.bitcoinj.protocols.channels.PaymentChannelCloseException包,在下文中一共展示了CloseReason类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: receiveClose
import org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason; //导入依赖的package包/类
@GuardedBy("lock")
private void receiveClose(Protos.TwoWayChannelMessage msg) throws VerificationException {
checkState(lock.isHeldByCurrentThread());
if (msg.hasSettlement()) {
Transaction settleTx = wallet.getParams().getDefaultSerializer().makeTransaction(msg.getSettlement().getTx().toByteArray());
log.info("CLOSE message received with settlement tx {}", settleTx.getHash());
// TODO: set source
if (state != null && state().isSettlementTransaction(settleTx)) {
// The wallet has a listener on it that the state object will use to do the right thing at this
// point (like watching it for confirmations). The tx has been checked by now for syntactical validity
// and that it correctly spends the multisig contract.
wallet.receivePending(settleTx, null);
}
} else {
log.info("CLOSE message received without settlement tx");
}
if (step == InitStep.WAITING_FOR_CHANNEL_CLOSE)
conn.destroyConnection(CloseReason.CLIENT_REQUESTED_CLOSE);
else
conn.destroyConnection(CloseReason.SERVER_REQUESTED_CLOSE);
step = InitStep.CHANNEL_CLOSED;
}
开发者ID:guodroid,项目名称:okwallet,代码行数:23,代码来源:PaymentChannelClient.java
示例2: settlePayment
import org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason; //导入依赖的package包/类
@GuardedBy("lock")
private void settlePayment(final CloseReason clientRequestedClose) throws InsufficientMoneyException {
// Setting channelSettling here prevents us from sending another CLOSE when state.close() calls
// close() on us here below via the stored channel state.
// TODO: Strongly separate the lifecycle of the payment channel from the TCP connection in these classes.
channelSettling = true;
ListenableFuture<KeyParameter> keyFuture = conn.getUserKey();
ListenableFuture<Transaction> result;
if (keyFuture != null) {
result = Futures.transformAsync(conn.getUserKey(), new AsyncFunction<KeyParameter, Transaction>() {
@Override
public ListenableFuture<Transaction> apply(KeyParameter userKey) throws Exception {
return state.close(userKey);
}
});
} else {
result = state.close();
}
Futures.addCallback(result, new FutureCallback<Transaction>() {
开发者ID:guodroid,项目名称:okwallet,代码行数:20,代码来源:PaymentChannelServer.java
示例3: settlePayment
import org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason; //导入依赖的package包/类
@GuardedBy("lock")
private void settlePayment(final CloseReason clientRequestedClose) throws InsufficientMoneyException {
// Setting channelSettling here prevents us from sending another CLOSE when state.close() calls
// close() on us here below via the stored channel state.
// TODO: Strongly separate the lifecycle of the payment channel from the TCP connection in these classes.
channelSettling = true;
ListenableFuture<KeyParameter> keyFuture = conn.getUserKey();
ListenableFuture<Transaction> result;
if (keyFuture != null) {
result = Futures.transform(conn.getUserKey(), new AsyncFunction<KeyParameter, Transaction>() {
@Override
public ListenableFuture<Transaction> apply(KeyParameter userKey) throws Exception {
return state.close(userKey);
}
});
} else {
result = state.close();
}
Futures.addCallback(result, new FutureCallback<Transaction>() {
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:20,代码来源:PaymentChannelServer.java
示例4: receiveClose
import org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason; //导入依赖的package包/类
@GuardedBy("lock")
private void receiveClose(Protos.TwoWayChannelMessage msg) throws VerificationException {
checkState(lock.isHeldByCurrentThread());
if (msg.hasSettlement()) {
Transaction settleTx = new Transaction(wallet.getParams(), msg.getSettlement().getTx().toByteArray());
log.info("CLOSE message received with settlement tx {}", settleTx.getHash());
// TODO: set source
if (state != null && state().isSettlementTransaction(settleTx)) {
// The wallet has a listener on it that the state object will use to do the right thing at this
// point (like watching it for confirmations). The tx has been checked by now for syntactical validity
// and that it correctly spends the multisig contract.
wallet.receivePending(settleTx, null);
}
} else {
log.info("CLOSE message received without settlement tx");
}
if (step == InitStep.WAITING_FOR_CHANNEL_CLOSE)
conn.destroyConnection(CloseReason.CLIENT_REQUESTED_CLOSE);
else
conn.destroyConnection(CloseReason.SERVER_REQUESTED_CLOSE);
step = InitStep.CHANNEL_CLOSED;
}
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:23,代码来源:PaymentChannelClient.java
示例5: error
import org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason; //导入依赖的package包/类
private void error(String message, Protos.Error.ErrorCode errorCode, CloseReason closeReason) {
log.error(message);
Protos.Error.Builder errorBuilder;
errorBuilder = Protos.Error.newBuilder()
.setCode(errorCode);
if (message != null)
errorBuilder.setExplanation(message);
conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
.setError(errorBuilder)
.setType(Protos.TwoWayChannelMessage.MessageType.ERROR)
.build());
conn.destroyConnection(closeReason);
}
开发者ID:guodroid,项目名称:okwallet,代码行数:14,代码来源:PaymentChannelServer.java
示例6: receiveCloseMessage
import org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason; //导入依赖的package包/类
@GuardedBy("lock")
private void receiveCloseMessage() throws InsufficientMoneyException {
log.info("Got CLOSE message, closing channel");
if (state != null) {
settlePayment(CloseReason.CLIENT_REQUESTED_CLOSE);
} else {
conn.destroyConnection(CloseReason.CLIENT_REQUESTED_CLOSE);
}
}
开发者ID:guodroid,项目名称:okwallet,代码行数:10,代码来源:PaymentChannelServer.java
示例7: close
import org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason; //导入依赖的package包/类
/**
* <p>Closes the connection by generating a settle message for the client and calls
* {@link org.bitcoinj.protocols.channels.PaymentChannelServer.ServerConnection#destroyConnection(org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason)}. Note that this does not broadcast
* the payment transaction and the client may still resume the same channel if they reconnect</p>
* <p>
* <p>Note that {@link PaymentChannelServer#connectionClosed()} must still be called after the connection fully
* closes.</p>
*/
public void close() {
lock.lock();
try {
if (connectionOpen && !channelSettling) {
final Protos.TwoWayChannelMessage.Builder msg = Protos.TwoWayChannelMessage.newBuilder();
msg.setType(Protos.TwoWayChannelMessage.MessageType.CLOSE);
conn.sendToClient(msg.build());
conn.destroyConnection(CloseReason.SERVER_REQUESTED_CLOSE);
}
} finally {
lock.unlock();
}
}
开发者ID:guodroid,项目名称:okwallet,代码行数:22,代码来源:PaymentChannelServer.java
示例8: error
import org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason; //导入依赖的package包/类
private void error(String message, Protos.Error.ErrorCode errorCode, CloseReason closeReason) {
log.error(message);
Protos.Error.Builder errorBuilder;
errorBuilder = Protos.Error.newBuilder()
.setCode(errorCode)
.setExplanation(message);
conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
.setError(errorBuilder)
.setType(Protos.TwoWayChannelMessage.MessageType.ERROR)
.build());
conn.destroyConnection(closeReason);
}
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:13,代码来源:PaymentChannelServer.java
示例9: close
import org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason; //导入依赖的package包/类
/**
* <p>Closes the connection by generating a settle message for the client and calls
* {@link ServerConnection#destroyConnection(CloseReason)}. Note that this does not broadcast
* the payment transaction and the client may still resume the same channel if they reconnect</p>
* <p>
* <p>Note that {@link PaymentChannelServer#connectionClosed()} must still be called after the connection fully
* closes.</p>
*/
public void close() {
lock.lock();
try {
if (connectionOpen && !channelSettling) {
final Protos.TwoWayChannelMessage.Builder msg = Protos.TwoWayChannelMessage.newBuilder();
msg.setType(Protos.TwoWayChannelMessage.MessageType.CLOSE);
conn.sendToClient(msg.build());
conn.destroyConnection(CloseReason.SERVER_REQUESTED_CLOSE);
}
} finally {
lock.unlock();
}
}
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:22,代码来源:PaymentChannelServer.java
示例10: settlePayment
import org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason; //导入依赖的package包/类
@GuardedBy("lock")
private void settlePayment(final CloseReason clientRequestedClose) throws InsufficientMoneyException {
// Setting channelSettling here prevents us from sending another CLOSE when state.close() calls
// close() on us here below via the stored channel state.
// TODO: Strongly separate the lifecycle of the payment channel from the TCP connection in these classes.
channelSettling = true;
Futures.addCallback(state.close(), new FutureCallback<Transaction>() {
@Override
public void onSuccess(Transaction result) {
// Send the successfully accepted transaction back to the client.
final Protos.TwoWayChannelMessage.Builder msg = Protos.TwoWayChannelMessage.newBuilder();
msg.setType(Protos.TwoWayChannelMessage.MessageType.CLOSE);
if (result != null) {
// Result can be null on various error paths, like if we never actually opened
// properly and so on.
msg.getSettlementBuilder().setTx(ByteString.copyFrom(result.bitcoinSerialize()));
log.info("Sending CLOSE back with broadcast settlement tx.");
} else {
log.info("Sending CLOSE back without broadcast settlement tx.");
}
conn.sendToClient(msg.build());
conn.destroyConnection(clientRequestedClose);
}
@Override
public void onFailure(Throwable t) {
log.error("Failed to broadcast settlement tx", t);
conn.destroyConnection(clientRequestedClose);
}
});
}
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:32,代码来源:PaymentChannelServer.java
示例11: settlePayment
import org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason; //导入依赖的package包/类
@GuardedBy("lock")
private void settlePayment(final CloseReason clientRequestedClose) throws InsufficientMoneyException {
// Setting channelSettling here prevents us from sending another CLOSE when state.close() calls
// close() on us here below via the stored channel state.
// TODO: Strongly separate the lifecycle of the payment channel from the TCP connection in these classes.
channelSettling = true;
Futures.addCallback(state.close(), new FutureCallback<Transaction>() {
@Override
public void onSuccess(Transaction result) {
// Send the successfully accepted transaction back to the client.
final Protos.TwoWayChannelMessage.Builder msg = Protos.TwoWayChannelMessage.newBuilder();
msg.setType(Protos.TwoWayChannelMessage.MessageType.CLOSE);
if (result != null) {
// Result can be null on various error paths, like if we never actually opened
// properly and so on.
msg.getSettlementBuilder().setTx(ByteString.copyFrom(result.unsafeBitcoinSerialize()));
log.info("Sending CLOSE back with broadcast settlement tx.");
} else {
log.info("Sending CLOSE back without broadcast settlement tx.");
}
conn.sendToClient(msg.build());
conn.destroyConnection(clientRequestedClose);
}
@Override
public void onFailure(Throwable t) {
log.error("Failed to broadcast settlement tx", t);
conn.destroyConnection(clientRequestedClose);
}
});
}
开发者ID:HashEngineering,项目名称:dashj,代码行数:32,代码来源:PaymentChannelServer.java
示例12: setIncreasePaymentFutureIfNeeded
import org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason; //导入依赖的package包/类
private void setIncreasePaymentFutureIfNeeded(PaymentChannelCloseException.CloseReason reason, String message) {
if (increasePaymentFuture != null && !increasePaymentFuture.isDone()) {
increasePaymentFuture.setException(new PaymentChannelCloseException(message, reason));
}
}
开发者ID:guodroid,项目名称:okwallet,代码行数:6,代码来源:PaymentChannelClient.java
示例13: receiveVersionMessage
import org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason; //导入依赖的package包/类
@GuardedBy("lock")
private void receiveVersionMessage(Protos.TwoWayChannelMessage msg) throws VerificationException {
checkState(step == InitStep.WAITING_ON_CLIENT_VERSION && msg.hasClientVersion());
final Protos.ClientVersion clientVersion = msg.getClientVersion();
majorVersion = clientVersion.getMajor();
if (!SERVER_VERSIONS.containsKey(majorVersion)) {
error("This server needs one of protocol versions " + SERVER_VERSIONS.keySet() + " , client offered " + majorVersion,
Protos.Error.ErrorCode.NO_ACCEPTABLE_VERSION, CloseReason.NO_ACCEPTABLE_VERSION);
return;
}
Protos.ServerVersion.Builder versionNegotiationBuilder = Protos.ServerVersion.newBuilder()
.setMajor(majorVersion).setMinor(SERVER_VERSIONS.get(majorVersion));
conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
.setType(Protos.TwoWayChannelMessage.MessageType.SERVER_VERSION)
.setServerVersion(versionNegotiationBuilder)
.build());
ByteString reopenChannelContractHash = clientVersion.getPreviousChannelContractHash();
if (reopenChannelContractHash != null && reopenChannelContractHash.size() == 32) {
Sha256Hash contractHash = Sha256Hash.wrap(reopenChannelContractHash.toByteArray());
log.info("New client that wants to resume {}", contractHash);
StoredPaymentChannelServerStates channels = (StoredPaymentChannelServerStates)
wallet.getExtensions().get(StoredPaymentChannelServerStates.EXTENSION_ID);
if (channels != null) {
StoredServerChannel storedServerChannel = channels.getChannel(contractHash);
if (storedServerChannel != null) {
final PaymentChannelServer existingHandler = storedServerChannel.setConnectedHandler(this, false);
if (existingHandler != this) {
log.warn(" ... and that channel is already in use, disconnecting other user.");
existingHandler.close();
storedServerChannel.setConnectedHandler(this, true);
}
log.info("Got resume version message, responding with VERSIONS and CHANNEL_OPEN");
state = storedServerChannel.getOrCreateState(wallet, broadcaster);
step = InitStep.CHANNEL_OPEN;
conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
.setType(Protos.TwoWayChannelMessage.MessageType.CHANNEL_OPEN)
.build());
conn.channelOpen(contractHash);
return;
} else {
log.error(" ... but we do not have any record of that contract! Resume failed.");
}
} else {
log.error(" ... but we do not have any stored channels! Resume failed.");
}
}
log.info("Got initial version message, responding with VERSIONS and INITIATE: min value={}",
minAcceptedChannelSize.value);
myKey = new ECKey();
wallet.freshReceiveKey();
expireTime = Utils.currentTimeSeconds() + truncateTimeWindow(clientVersion.getTimeWindowSecs());
switch (majorVersion) {
case 1:
step = InitStep.WAITING_ON_UNSIGNED_REFUND;
break;
case 2:
step = InitStep.WAITING_ON_CONTRACT;
break;
default:
error("Protocol version " + majorVersion + " not supported", Protos.Error.ErrorCode.NO_ACCEPTABLE_VERSION, CloseReason.NO_ACCEPTABLE_VERSION);
break;
}
Protos.Initiate.Builder initiateBuilder = Protos.Initiate.newBuilder()
.setMultisigKey(ByteString.copyFrom(myKey.getPubKey()))
.setExpireTimeSecs(expireTime)
.setMinAcceptedChannelSize(minAcceptedChannelSize.value)
.setMinPayment(minPayment.value);
conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
.setInitiate(initiateBuilder)
.setType(Protos.TwoWayChannelMessage.MessageType.INITIATE)
.build());
}
开发者ID:guodroid,项目名称:okwallet,代码行数:79,代码来源:PaymentChannelServer.java
示例14: receiveInitiate
import org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason; //导入依赖的package包/类
@Nullable
@GuardedBy("lock")
private CloseReason receiveInitiate(Protos.Initiate initiate, Coin contractValue, Protos.Error.Builder errorBuilder) throws VerificationException, InsufficientMoneyException {
log.info("Got INITIATE message:\n{}", initiate.toString());
final long expireTime = initiate.getExpireTimeSecs();
checkState( expireTime >= 0 && initiate.getMinAcceptedChannelSize() >= 0);
if (! conn.acceptExpireTime(expireTime)) {
log.error("Server suggested expire time was out of our allowed bounds: {} ({} s)", dateFormat.format(new Date(expireTime * 1000)), expireTime);
errorBuilder.setCode(Protos.Error.ErrorCode.TIME_WINDOW_UNACCEPTABLE);
return CloseReason.TIME_WINDOW_UNACCEPTABLE;
}
Coin minChannelSize = Coin.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.value;
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 = Coin.valueOf(initiate.getMinPayment() - MIN_PAYMENT);
return CloseReason.SERVER_REQUESTED_TOO_MUCH_VALUE;
}
final byte[] pubKeyBytes = initiate.getMultisigKey().toByteArray();
if (!ECKey.isPubKeyCanonical(pubKeyBytes))
throw new VerificationException("Server gave us a non-canonical public key, protocol error.");
state = new PaymentChannelClientState(wallet, myKey, ECKey.fromPublicOnly(pubKeyBytes), contractValue, expireTime);
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,项目名称:namecoinj,代码行数:58,代码来源:PaymentChannelClient.java
注:本文中的org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论