From c98badcf1c04da7e0e596a1778cddb50cbd3b50c Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 10 Jul 2013 18:36:26 +0200 Subject: [PATCH] Store states in protobufs instead of using Java Serialization. Saves having to use reflection. --- .../protocols/channels/ClientState.java | 1317 +++++++++++++++++ .../protocols/channels/ServerState.java | 1310 ++++++++++++++++ .../StoredPaymentChannelClientStates.java | 40 +- .../StoredPaymentChannelServerStates.java | 38 +- .../channels/StoredServerChannel.java | 6 +- core/src/storedclientpaymentchannel.proto | 45 + core/src/storedserverpaymentchannel.proto | 44 + 7 files changed, 2775 insertions(+), 25 deletions(-) create mode 100644 core/src/main/java/com/google/bitcoin/protocols/channels/ClientState.java create mode 100644 core/src/main/java/com/google/bitcoin/protocols/channels/ServerState.java create mode 100644 core/src/storedclientpaymentchannel.proto create mode 100644 core/src/storedserverpaymentchannel.proto diff --git a/core/src/main/java/com/google/bitcoin/protocols/channels/ClientState.java b/core/src/main/java/com/google/bitcoin/protocols/channels/ClientState.java new file mode 100644 index 00000000..cd9bced7 --- /dev/null +++ b/core/src/main/java/com/google/bitcoin/protocols/channels/ClientState.java @@ -0,0 +1,1317 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: storedclientpaymentchannel.proto + +package com.google.bitcoin.protocols.channels; + +public final class ClientState { + private ClientState() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + } + public interface StoredClientPaymentChannelsOrBuilder + extends com.google.protobuf.MessageOrBuilder { + + // repeated .paymentchannels.StoredClientPaymentChannel channels = 1; + java.util.List + getChannelsList(); + com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel getChannels(int index); + int getChannelsCount(); + java.util.List + getChannelsOrBuilderList(); + com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannelOrBuilder getChannelsOrBuilder( + int index); + } + public static final class StoredClientPaymentChannels extends + com.google.protobuf.GeneratedMessage + implements StoredClientPaymentChannelsOrBuilder { + // Use StoredClientPaymentChannels.newBuilder() to construct. + private StoredClientPaymentChannels(Builder builder) { + super(builder); + } + private StoredClientPaymentChannels(boolean noInit) {} + + private static final StoredClientPaymentChannels defaultInstance; + public static StoredClientPaymentChannels getDefaultInstance() { + return defaultInstance; + } + + public StoredClientPaymentChannels getDefaultInstanceForType() { + return defaultInstance; + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.google.bitcoin.protocols.channels.ClientState.internal_static_paymentchannels_StoredClientPaymentChannels_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.bitcoin.protocols.channels.ClientState.internal_static_paymentchannels_StoredClientPaymentChannels_fieldAccessorTable; + } + + // repeated .paymentchannels.StoredClientPaymentChannel channels = 1; + public static final int CHANNELS_FIELD_NUMBER = 1; + private java.util.List channels_; + public java.util.List getChannelsList() { + return channels_; + } + public java.util.List + getChannelsOrBuilderList() { + return channels_; + } + public int getChannelsCount() { + return channels_.size(); + } + public com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel getChannels(int index) { + return channels_.get(index); + } + public com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannelOrBuilder getChannelsOrBuilder( + int index) { + return channels_.get(index); + } + + private void initFields() { + channels_ = java.util.Collections.emptyList(); + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized != -1) return isInitialized == 1; + + for (int i = 0; i < getChannelsCount(); i++) { + if (!getChannels(i).isInitialized()) { + memoizedIsInitialized = 0; + return false; + } + } + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + for (int i = 0; i < channels_.size(); i++) { + output.writeMessage(1, channels_.get(i)); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + for (int i = 0; i < channels_.size(); i++) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(1, channels_.get(i)); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + @java.lang.Override + protected java.lang.Object writeReplace() + throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels parseFrom(java.io.InputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input, extensionRegistry)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder + implements com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannelsOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.google.bitcoin.protocols.channels.ClientState.internal_static_paymentchannels_StoredClientPaymentChannels_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.bitcoin.protocols.channels.ClientState.internal_static_paymentchannels_StoredClientPaymentChannels_fieldAccessorTable; + } + + // Construct using com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + getChannelsFieldBuilder(); + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + if (channelsBuilder_ == null) { + channels_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000001); + } else { + channelsBuilder_.clear(); + } + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels.getDescriptor(); + } + + public com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels getDefaultInstanceForType() { + return com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels.getDefaultInstance(); + } + + public com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels build() { + com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + private com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels buildParsed() + throws com.google.protobuf.InvalidProtocolBufferException { + com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException( + result).asInvalidProtocolBufferException(); + } + return result; + } + + public com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels buildPartial() { + com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels result = new com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels(this); + int from_bitField0_ = bitField0_; + if (channelsBuilder_ == null) { + if (((bitField0_ & 0x00000001) == 0x00000001)) { + channels_ = java.util.Collections.unmodifiableList(channels_); + bitField0_ = (bitField0_ & ~0x00000001); + } + result.channels_ = channels_; + } else { + result.channels_ = channelsBuilder_.build(); + } + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels) { + return mergeFrom((com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels other) { + if (other == com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels.getDefaultInstance()) return this; + if (channelsBuilder_ == null) { + if (!other.channels_.isEmpty()) { + if (channels_.isEmpty()) { + channels_ = other.channels_; + bitField0_ = (bitField0_ & ~0x00000001); + } else { + ensureChannelsIsMutable(); + channels_.addAll(other.channels_); + } + onChanged(); + } + } else { + if (!other.channels_.isEmpty()) { + if (channelsBuilder_.isEmpty()) { + channelsBuilder_.dispose(); + channelsBuilder_ = null; + channels_ = other.channels_; + bitField0_ = (bitField0_ & ~0x00000001); + channelsBuilder_ = + com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? + getChannelsFieldBuilder() : null; + } else { + channelsBuilder_.addAllMessages(other.channels_); + } + } + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + for (int i = 0; i < getChannelsCount(); i++) { + if (!getChannels(i).isInitialized()) { + + return false; + } + } + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder( + this.getUnknownFields()); + while (true) { + int tag = input.readTag(); + switch (tag) { + case 0: + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + } + break; + } + case 10: { + com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.Builder subBuilder = com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.newBuilder(); + input.readMessage(subBuilder, extensionRegistry); + addChannels(subBuilder.buildPartial()); + break; + } + } + } + } + + private int bitField0_; + + // repeated .paymentchannels.StoredClientPaymentChannel channels = 1; + private java.util.List channels_ = + java.util.Collections.emptyList(); + private void ensureChannelsIsMutable() { + if (!((bitField0_ & 0x00000001) == 0x00000001)) { + channels_ = new java.util.ArrayList(channels_); + bitField0_ |= 0x00000001; + } + } + + private com.google.protobuf.RepeatedFieldBuilder< + com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel, com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.Builder, com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannelOrBuilder> channelsBuilder_; + + public java.util.List getChannelsList() { + if (channelsBuilder_ == null) { + return java.util.Collections.unmodifiableList(channels_); + } else { + return channelsBuilder_.getMessageList(); + } + } + public int getChannelsCount() { + if (channelsBuilder_ == null) { + return channels_.size(); + } else { + return channelsBuilder_.getCount(); + } + } + public com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel getChannels(int index) { + if (channelsBuilder_ == null) { + return channels_.get(index); + } else { + return channelsBuilder_.getMessage(index); + } + } + public Builder setChannels( + int index, com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel value) { + if (channelsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureChannelsIsMutable(); + channels_.set(index, value); + onChanged(); + } else { + channelsBuilder_.setMessage(index, value); + } + return this; + } + public Builder setChannels( + int index, com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.Builder builderForValue) { + if (channelsBuilder_ == null) { + ensureChannelsIsMutable(); + channels_.set(index, builderForValue.build()); + onChanged(); + } else { + channelsBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + public Builder addChannels(com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel value) { + if (channelsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureChannelsIsMutable(); + channels_.add(value); + onChanged(); + } else { + channelsBuilder_.addMessage(value); + } + return this; + } + public Builder addChannels( + int index, com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel value) { + if (channelsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureChannelsIsMutable(); + channels_.add(index, value); + onChanged(); + } else { + channelsBuilder_.addMessage(index, value); + } + return this; + } + public Builder addChannels( + com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.Builder builderForValue) { + if (channelsBuilder_ == null) { + ensureChannelsIsMutable(); + channels_.add(builderForValue.build()); + onChanged(); + } else { + channelsBuilder_.addMessage(builderForValue.build()); + } + return this; + } + public Builder addChannels( + int index, com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.Builder builderForValue) { + if (channelsBuilder_ == null) { + ensureChannelsIsMutable(); + channels_.add(index, builderForValue.build()); + onChanged(); + } else { + channelsBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + public Builder addAllChannels( + java.lang.Iterable values) { + if (channelsBuilder_ == null) { + ensureChannelsIsMutable(); + super.addAll(values, channels_); + onChanged(); + } else { + channelsBuilder_.addAllMessages(values); + } + return this; + } + public Builder clearChannels() { + if (channelsBuilder_ == null) { + channels_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + } else { + channelsBuilder_.clear(); + } + return this; + } + public Builder removeChannels(int index) { + if (channelsBuilder_ == null) { + ensureChannelsIsMutable(); + channels_.remove(index); + onChanged(); + } else { + channelsBuilder_.remove(index); + } + return this; + } + public com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.Builder getChannelsBuilder( + int index) { + return getChannelsFieldBuilder().getBuilder(index); + } + public com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannelOrBuilder getChannelsOrBuilder( + int index) { + if (channelsBuilder_ == null) { + return channels_.get(index); } else { + return channelsBuilder_.getMessageOrBuilder(index); + } + } + public java.util.List + getChannelsOrBuilderList() { + if (channelsBuilder_ != null) { + return channelsBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(channels_); + } + } + public com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.Builder addChannelsBuilder() { + return getChannelsFieldBuilder().addBuilder( + com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.getDefaultInstance()); + } + public com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.Builder addChannelsBuilder( + int index) { + return getChannelsFieldBuilder().addBuilder( + index, com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.getDefaultInstance()); + } + public java.util.List + getChannelsBuilderList() { + return getChannelsFieldBuilder().getBuilderList(); + } + private com.google.protobuf.RepeatedFieldBuilder< + com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel, com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.Builder, com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannelOrBuilder> + getChannelsFieldBuilder() { + if (channelsBuilder_ == null) { + channelsBuilder_ = new com.google.protobuf.RepeatedFieldBuilder< + com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel, com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.Builder, com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannelOrBuilder>( + channels_, + ((bitField0_ & 0x00000001) == 0x00000001), + getParentForChildren(), + isClean()); + channels_ = null; + } + return channelsBuilder_; + } + + // @@protoc_insertion_point(builder_scope:paymentchannels.StoredClientPaymentChannels) + } + + static { + defaultInstance = new StoredClientPaymentChannels(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:paymentchannels.StoredClientPaymentChannels) + } + + public interface StoredClientPaymentChannelOrBuilder + extends com.google.protobuf.MessageOrBuilder { + + // required bytes id = 1; + boolean hasId(); + com.google.protobuf.ByteString getId(); + + // required bytes contractTransaction = 2; + boolean hasContractTransaction(); + com.google.protobuf.ByteString getContractTransaction(); + + // required bytes refundTransaction = 3; + boolean hasRefundTransaction(); + com.google.protobuf.ByteString getRefundTransaction(); + + // required bytes myKey = 4; + boolean hasMyKey(); + com.google.protobuf.ByteString getMyKey(); + + // required uint64 valueToMe = 5; + boolean hasValueToMe(); + long getValueToMe(); + + // required uint64 refundFees = 6; + boolean hasRefundFees(); + long getRefundFees(); + } + public static final class StoredClientPaymentChannel extends + com.google.protobuf.GeneratedMessage + implements StoredClientPaymentChannelOrBuilder { + // Use StoredClientPaymentChannel.newBuilder() to construct. + private StoredClientPaymentChannel(Builder builder) { + super(builder); + } + private StoredClientPaymentChannel(boolean noInit) {} + + private static final StoredClientPaymentChannel defaultInstance; + public static StoredClientPaymentChannel getDefaultInstance() { + return defaultInstance; + } + + public StoredClientPaymentChannel getDefaultInstanceForType() { + return defaultInstance; + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.google.bitcoin.protocols.channels.ClientState.internal_static_paymentchannels_StoredClientPaymentChannel_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.bitcoin.protocols.channels.ClientState.internal_static_paymentchannels_StoredClientPaymentChannel_fieldAccessorTable; + } + + private int bitField0_; + // required bytes id = 1; + public static final int ID_FIELD_NUMBER = 1; + private com.google.protobuf.ByteString id_; + public boolean hasId() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public com.google.protobuf.ByteString getId() { + return id_; + } + + // required bytes contractTransaction = 2; + public static final int CONTRACTTRANSACTION_FIELD_NUMBER = 2; + private com.google.protobuf.ByteString contractTransaction_; + public boolean hasContractTransaction() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + public com.google.protobuf.ByteString getContractTransaction() { + return contractTransaction_; + } + + // required bytes refundTransaction = 3; + public static final int REFUNDTRANSACTION_FIELD_NUMBER = 3; + private com.google.protobuf.ByteString refundTransaction_; + public boolean hasRefundTransaction() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + public com.google.protobuf.ByteString getRefundTransaction() { + return refundTransaction_; + } + + // required bytes myKey = 4; + public static final int MYKEY_FIELD_NUMBER = 4; + private com.google.protobuf.ByteString myKey_; + public boolean hasMyKey() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + public com.google.protobuf.ByteString getMyKey() { + return myKey_; + } + + // required uint64 valueToMe = 5; + public static final int VALUETOME_FIELD_NUMBER = 5; + private long valueToMe_; + public boolean hasValueToMe() { + return ((bitField0_ & 0x00000010) == 0x00000010); + } + public long getValueToMe() { + return valueToMe_; + } + + // required uint64 refundFees = 6; + public static final int REFUNDFEES_FIELD_NUMBER = 6; + private long refundFees_; + public boolean hasRefundFees() { + return ((bitField0_ & 0x00000020) == 0x00000020); + } + public long getRefundFees() { + return refundFees_; + } + + private void initFields() { + id_ = com.google.protobuf.ByteString.EMPTY; + contractTransaction_ = com.google.protobuf.ByteString.EMPTY; + refundTransaction_ = com.google.protobuf.ByteString.EMPTY; + myKey_ = com.google.protobuf.ByteString.EMPTY; + valueToMe_ = 0L; + refundFees_ = 0L; + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized != -1) return isInitialized == 1; + + if (!hasId()) { + memoizedIsInitialized = 0; + return false; + } + if (!hasContractTransaction()) { + memoizedIsInitialized = 0; + return false; + } + if (!hasRefundTransaction()) { + memoizedIsInitialized = 0; + return false; + } + if (!hasMyKey()) { + memoizedIsInitialized = 0; + return false; + } + if (!hasValueToMe()) { + memoizedIsInitialized = 0; + return false; + } + if (!hasRefundFees()) { + memoizedIsInitialized = 0; + return false; + } + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeBytes(1, id_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeBytes(2, contractTransaction_); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + output.writeBytes(3, refundTransaction_); + } + if (((bitField0_ & 0x00000008) == 0x00000008)) { + output.writeBytes(4, myKey_); + } + if (((bitField0_ & 0x00000010) == 0x00000010)) { + output.writeUInt64(5, valueToMe_); + } + if (((bitField0_ & 0x00000020) == 0x00000020)) { + output.writeUInt64(6, refundFees_); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(1, id_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(2, contractTransaction_); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(3, refundTransaction_); + } + if (((bitField0_ & 0x00000008) == 0x00000008)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(4, myKey_); + } + if (((bitField0_ & 0x00000010) == 0x00000010)) { + size += com.google.protobuf.CodedOutputStream + .computeUInt64Size(5, valueToMe_); + } + if (((bitField0_ & 0x00000020) == 0x00000020)) { + size += com.google.protobuf.CodedOutputStream + .computeUInt64Size(6, refundFees_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + @java.lang.Override + protected java.lang.Object writeReplace() + throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel parseFrom(java.io.InputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input, extensionRegistry)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder + implements com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannelOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.google.bitcoin.protocols.channels.ClientState.internal_static_paymentchannels_StoredClientPaymentChannel_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.bitcoin.protocols.channels.ClientState.internal_static_paymentchannels_StoredClientPaymentChannel_fieldAccessorTable; + } + + // Construct using com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + id_ = com.google.protobuf.ByteString.EMPTY; + bitField0_ = (bitField0_ & ~0x00000001); + contractTransaction_ = com.google.protobuf.ByteString.EMPTY; + bitField0_ = (bitField0_ & ~0x00000002); + refundTransaction_ = com.google.protobuf.ByteString.EMPTY; + bitField0_ = (bitField0_ & ~0x00000004); + myKey_ = com.google.protobuf.ByteString.EMPTY; + bitField0_ = (bitField0_ & ~0x00000008); + valueToMe_ = 0L; + bitField0_ = (bitField0_ & ~0x00000010); + refundFees_ = 0L; + bitField0_ = (bitField0_ & ~0x00000020); + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.getDescriptor(); + } + + public com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel getDefaultInstanceForType() { + return com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.getDefaultInstance(); + } + + public com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel build() { + com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + private com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel buildParsed() + throws com.google.protobuf.InvalidProtocolBufferException { + com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException( + result).asInvalidProtocolBufferException(); + } + return result; + } + + public com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel buildPartial() { + com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel result = new com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.id_ = id_; + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; + } + result.contractTransaction_ = contractTransaction_; + if (((from_bitField0_ & 0x00000004) == 0x00000004)) { + to_bitField0_ |= 0x00000004; + } + result.refundTransaction_ = refundTransaction_; + if (((from_bitField0_ & 0x00000008) == 0x00000008)) { + to_bitField0_ |= 0x00000008; + } + result.myKey_ = myKey_; + if (((from_bitField0_ & 0x00000010) == 0x00000010)) { + to_bitField0_ |= 0x00000010; + } + result.valueToMe_ = valueToMe_; + if (((from_bitField0_ & 0x00000020) == 0x00000020)) { + to_bitField0_ |= 0x00000020; + } + result.refundFees_ = refundFees_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel) { + return mergeFrom((com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel other) { + if (other == com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.getDefaultInstance()) return this; + if (other.hasId()) { + setId(other.getId()); + } + if (other.hasContractTransaction()) { + setContractTransaction(other.getContractTransaction()); + } + if (other.hasRefundTransaction()) { + setRefundTransaction(other.getRefundTransaction()); + } + if (other.hasMyKey()) { + setMyKey(other.getMyKey()); + } + if (other.hasValueToMe()) { + setValueToMe(other.getValueToMe()); + } + if (other.hasRefundFees()) { + setRefundFees(other.getRefundFees()); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + if (!hasId()) { + + return false; + } + if (!hasContractTransaction()) { + + return false; + } + if (!hasRefundTransaction()) { + + return false; + } + if (!hasMyKey()) { + + return false; + } + if (!hasValueToMe()) { + + return false; + } + if (!hasRefundFees()) { + + return false; + } + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder( + this.getUnknownFields()); + while (true) { + int tag = input.readTag(); + switch (tag) { + case 0: + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + } + break; + } + case 10: { + bitField0_ |= 0x00000001; + id_ = input.readBytes(); + break; + } + case 18: { + bitField0_ |= 0x00000002; + contractTransaction_ = input.readBytes(); + break; + } + case 26: { + bitField0_ |= 0x00000004; + refundTransaction_ = input.readBytes(); + break; + } + case 34: { + bitField0_ |= 0x00000008; + myKey_ = input.readBytes(); + break; + } + case 40: { + bitField0_ |= 0x00000010; + valueToMe_ = input.readUInt64(); + break; + } + case 48: { + bitField0_ |= 0x00000020; + refundFees_ = input.readUInt64(); + break; + } + } + } + } + + private int bitField0_; + + // required bytes id = 1; + private com.google.protobuf.ByteString id_ = com.google.protobuf.ByteString.EMPTY; + public boolean hasId() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public com.google.protobuf.ByteString getId() { + return id_; + } + public Builder setId(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + id_ = value; + onChanged(); + return this; + } + public Builder clearId() { + bitField0_ = (bitField0_ & ~0x00000001); + id_ = getDefaultInstance().getId(); + onChanged(); + return this; + } + + // required bytes contractTransaction = 2; + private com.google.protobuf.ByteString contractTransaction_ = com.google.protobuf.ByteString.EMPTY; + public boolean hasContractTransaction() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + public com.google.protobuf.ByteString getContractTransaction() { + return contractTransaction_; + } + public Builder setContractTransaction(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000002; + contractTransaction_ = value; + onChanged(); + return this; + } + public Builder clearContractTransaction() { + bitField0_ = (bitField0_ & ~0x00000002); + contractTransaction_ = getDefaultInstance().getContractTransaction(); + onChanged(); + return this; + } + + // required bytes refundTransaction = 3; + private com.google.protobuf.ByteString refundTransaction_ = com.google.protobuf.ByteString.EMPTY; + public boolean hasRefundTransaction() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + public com.google.protobuf.ByteString getRefundTransaction() { + return refundTransaction_; + } + public Builder setRefundTransaction(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + refundTransaction_ = value; + onChanged(); + return this; + } + public Builder clearRefundTransaction() { + bitField0_ = (bitField0_ & ~0x00000004); + refundTransaction_ = getDefaultInstance().getRefundTransaction(); + onChanged(); + return this; + } + + // required bytes myKey = 4; + private com.google.protobuf.ByteString myKey_ = com.google.protobuf.ByteString.EMPTY; + public boolean hasMyKey() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + public com.google.protobuf.ByteString getMyKey() { + return myKey_; + } + public Builder setMyKey(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000008; + myKey_ = value; + onChanged(); + return this; + } + public Builder clearMyKey() { + bitField0_ = (bitField0_ & ~0x00000008); + myKey_ = getDefaultInstance().getMyKey(); + onChanged(); + return this; + } + + // required uint64 valueToMe = 5; + private long valueToMe_ ; + public boolean hasValueToMe() { + return ((bitField0_ & 0x00000010) == 0x00000010); + } + public long getValueToMe() { + return valueToMe_; + } + public Builder setValueToMe(long value) { + bitField0_ |= 0x00000010; + valueToMe_ = value; + onChanged(); + return this; + } + public Builder clearValueToMe() { + bitField0_ = (bitField0_ & ~0x00000010); + valueToMe_ = 0L; + onChanged(); + return this; + } + + // required uint64 refundFees = 6; + private long refundFees_ ; + public boolean hasRefundFees() { + return ((bitField0_ & 0x00000020) == 0x00000020); + } + public long getRefundFees() { + return refundFees_; + } + public Builder setRefundFees(long value) { + bitField0_ |= 0x00000020; + refundFees_ = value; + onChanged(); + return this; + } + public Builder clearRefundFees() { + bitField0_ = (bitField0_ & ~0x00000020); + refundFees_ = 0L; + onChanged(); + return this; + } + + // @@protoc_insertion_point(builder_scope:paymentchannels.StoredClientPaymentChannel) + } + + static { + defaultInstance = new StoredClientPaymentChannel(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:paymentchannels.StoredClientPaymentChannel) + } + + private static com.google.protobuf.Descriptors.Descriptor + internal_static_paymentchannels_StoredClientPaymentChannels_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_paymentchannels_StoredClientPaymentChannels_fieldAccessorTable; + private static com.google.protobuf.Descriptors.Descriptor + internal_static_paymentchannels_StoredClientPaymentChannel_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_paymentchannels_StoredClientPaymentChannel_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n storedclientpaymentchannel.proto\022\017paym" + + "entchannels\"\\\n\033StoredClientPaymentChanne" + + "ls\022=\n\010channels\030\001 \003(\0132+.paymentchannels.S" + + "toredClientPaymentChannel\"\226\001\n\032StoredClie" + + "ntPaymentChannel\022\n\n\002id\030\001 \002(\014\022\033\n\023contract" + + "Transaction\030\002 \002(\014\022\031\n\021refundTransaction\030\003" + + " \002(\014\022\r\n\005myKey\030\004 \002(\014\022\021\n\tvalueToMe\030\005 \002(\004\022\022" + + "\n\nrefundFees\030\006 \002(\004B4\n%com.google.bitcoin" + + ".protocols.channelsB\013ClientState" + }; + com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = + new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { + public com.google.protobuf.ExtensionRegistry assignDescriptors( + com.google.protobuf.Descriptors.FileDescriptor root) { + descriptor = root; + internal_static_paymentchannels_StoredClientPaymentChannels_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_paymentchannels_StoredClientPaymentChannels_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_paymentchannels_StoredClientPaymentChannels_descriptor, + new java.lang.String[] { "Channels", }, + com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels.class, + com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannels.Builder.class); + internal_static_paymentchannels_StoredClientPaymentChannel_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_paymentchannels_StoredClientPaymentChannel_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_paymentchannels_StoredClientPaymentChannel_descriptor, + new java.lang.String[] { "Id", "ContractTransaction", "RefundTransaction", "MyKey", "ValueToMe", "RefundFees", }, + com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.class, + com.google.bitcoin.protocols.channels.ClientState.StoredClientPaymentChannel.Builder.class); + return null; + } + }; + com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }, assigner); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/core/src/main/java/com/google/bitcoin/protocols/channels/ServerState.java b/core/src/main/java/com/google/bitcoin/protocols/channels/ServerState.java new file mode 100644 index 00000000..a1565bc1 --- /dev/null +++ b/core/src/main/java/com/google/bitcoin/protocols/channels/ServerState.java @@ -0,0 +1,1310 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: storedserverpaymentchannel.proto + +package com.google.bitcoin.protocols.channels; + +public final class ServerState { + private ServerState() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + } + public interface StoredServerPaymentChannelsOrBuilder + extends com.google.protobuf.MessageOrBuilder { + + // repeated .paymentchannels.StoredServerPaymentChannel channels = 1; + java.util.List + getChannelsList(); + com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel getChannels(int index); + int getChannelsCount(); + java.util.List + getChannelsOrBuilderList(); + com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannelOrBuilder getChannelsOrBuilder( + int index); + } + public static final class StoredServerPaymentChannels extends + com.google.protobuf.GeneratedMessage + implements StoredServerPaymentChannelsOrBuilder { + // Use StoredServerPaymentChannels.newBuilder() to construct. + private StoredServerPaymentChannels(Builder builder) { + super(builder); + } + private StoredServerPaymentChannels(boolean noInit) {} + + private static final StoredServerPaymentChannels defaultInstance; + public static StoredServerPaymentChannels getDefaultInstance() { + return defaultInstance; + } + + public StoredServerPaymentChannels getDefaultInstanceForType() { + return defaultInstance; + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.google.bitcoin.protocols.channels.ServerState.internal_static_paymentchannels_StoredServerPaymentChannels_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.bitcoin.protocols.channels.ServerState.internal_static_paymentchannels_StoredServerPaymentChannels_fieldAccessorTable; + } + + // repeated .paymentchannels.StoredServerPaymentChannel channels = 1; + public static final int CHANNELS_FIELD_NUMBER = 1; + private java.util.List channels_; + public java.util.List getChannelsList() { + return channels_; + } + public java.util.List + getChannelsOrBuilderList() { + return channels_; + } + public int getChannelsCount() { + return channels_.size(); + } + public com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel getChannels(int index) { + return channels_.get(index); + } + public com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannelOrBuilder getChannelsOrBuilder( + int index) { + return channels_.get(index); + } + + private void initFields() { + channels_ = java.util.Collections.emptyList(); + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized != -1) return isInitialized == 1; + + for (int i = 0; i < getChannelsCount(); i++) { + if (!getChannels(i).isInitialized()) { + memoizedIsInitialized = 0; + return false; + } + } + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + for (int i = 0; i < channels_.size(); i++) { + output.writeMessage(1, channels_.get(i)); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + for (int i = 0; i < channels_.size(); i++) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(1, channels_.get(i)); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + @java.lang.Override + protected java.lang.Object writeReplace() + throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels parseFrom(java.io.InputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input, extensionRegistry)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder + implements com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannelsOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.google.bitcoin.protocols.channels.ServerState.internal_static_paymentchannels_StoredServerPaymentChannels_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.bitcoin.protocols.channels.ServerState.internal_static_paymentchannels_StoredServerPaymentChannels_fieldAccessorTable; + } + + // Construct using com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + getChannelsFieldBuilder(); + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + if (channelsBuilder_ == null) { + channels_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000001); + } else { + channelsBuilder_.clear(); + } + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels.getDescriptor(); + } + + public com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels getDefaultInstanceForType() { + return com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels.getDefaultInstance(); + } + + public com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels build() { + com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + private com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels buildParsed() + throws com.google.protobuf.InvalidProtocolBufferException { + com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException( + result).asInvalidProtocolBufferException(); + } + return result; + } + + public com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels buildPartial() { + com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels result = new com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels(this); + int from_bitField0_ = bitField0_; + if (channelsBuilder_ == null) { + if (((bitField0_ & 0x00000001) == 0x00000001)) { + channels_ = java.util.Collections.unmodifiableList(channels_); + bitField0_ = (bitField0_ & ~0x00000001); + } + result.channels_ = channels_; + } else { + result.channels_ = channelsBuilder_.build(); + } + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels) { + return mergeFrom((com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels other) { + if (other == com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels.getDefaultInstance()) return this; + if (channelsBuilder_ == null) { + if (!other.channels_.isEmpty()) { + if (channels_.isEmpty()) { + channels_ = other.channels_; + bitField0_ = (bitField0_ & ~0x00000001); + } else { + ensureChannelsIsMutable(); + channels_.addAll(other.channels_); + } + onChanged(); + } + } else { + if (!other.channels_.isEmpty()) { + if (channelsBuilder_.isEmpty()) { + channelsBuilder_.dispose(); + channelsBuilder_ = null; + channels_ = other.channels_; + bitField0_ = (bitField0_ & ~0x00000001); + channelsBuilder_ = + com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? + getChannelsFieldBuilder() : null; + } else { + channelsBuilder_.addAllMessages(other.channels_); + } + } + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + for (int i = 0; i < getChannelsCount(); i++) { + if (!getChannels(i).isInitialized()) { + + return false; + } + } + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder( + this.getUnknownFields()); + while (true) { + int tag = input.readTag(); + switch (tag) { + case 0: + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + } + break; + } + case 10: { + com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.Builder subBuilder = com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.newBuilder(); + input.readMessage(subBuilder, extensionRegistry); + addChannels(subBuilder.buildPartial()); + break; + } + } + } + } + + private int bitField0_; + + // repeated .paymentchannels.StoredServerPaymentChannel channels = 1; + private java.util.List channels_ = + java.util.Collections.emptyList(); + private void ensureChannelsIsMutable() { + if (!((bitField0_ & 0x00000001) == 0x00000001)) { + channels_ = new java.util.ArrayList(channels_); + bitField0_ |= 0x00000001; + } + } + + private com.google.protobuf.RepeatedFieldBuilder< + com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel, com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.Builder, com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannelOrBuilder> channelsBuilder_; + + public java.util.List getChannelsList() { + if (channelsBuilder_ == null) { + return java.util.Collections.unmodifiableList(channels_); + } else { + return channelsBuilder_.getMessageList(); + } + } + public int getChannelsCount() { + if (channelsBuilder_ == null) { + return channels_.size(); + } else { + return channelsBuilder_.getCount(); + } + } + public com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel getChannels(int index) { + if (channelsBuilder_ == null) { + return channels_.get(index); + } else { + return channelsBuilder_.getMessage(index); + } + } + public Builder setChannels( + int index, com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel value) { + if (channelsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureChannelsIsMutable(); + channels_.set(index, value); + onChanged(); + } else { + channelsBuilder_.setMessage(index, value); + } + return this; + } + public Builder setChannels( + int index, com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.Builder builderForValue) { + if (channelsBuilder_ == null) { + ensureChannelsIsMutable(); + channels_.set(index, builderForValue.build()); + onChanged(); + } else { + channelsBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + public Builder addChannels(com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel value) { + if (channelsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureChannelsIsMutable(); + channels_.add(value); + onChanged(); + } else { + channelsBuilder_.addMessage(value); + } + return this; + } + public Builder addChannels( + int index, com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel value) { + if (channelsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureChannelsIsMutable(); + channels_.add(index, value); + onChanged(); + } else { + channelsBuilder_.addMessage(index, value); + } + return this; + } + public Builder addChannels( + com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.Builder builderForValue) { + if (channelsBuilder_ == null) { + ensureChannelsIsMutable(); + channels_.add(builderForValue.build()); + onChanged(); + } else { + channelsBuilder_.addMessage(builderForValue.build()); + } + return this; + } + public Builder addChannels( + int index, com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.Builder builderForValue) { + if (channelsBuilder_ == null) { + ensureChannelsIsMutable(); + channels_.add(index, builderForValue.build()); + onChanged(); + } else { + channelsBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + public Builder addAllChannels( + java.lang.Iterable values) { + if (channelsBuilder_ == null) { + ensureChannelsIsMutable(); + super.addAll(values, channels_); + onChanged(); + } else { + channelsBuilder_.addAllMessages(values); + } + return this; + } + public Builder clearChannels() { + if (channelsBuilder_ == null) { + channels_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + } else { + channelsBuilder_.clear(); + } + return this; + } + public Builder removeChannels(int index) { + if (channelsBuilder_ == null) { + ensureChannelsIsMutable(); + channels_.remove(index); + onChanged(); + } else { + channelsBuilder_.remove(index); + } + return this; + } + public com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.Builder getChannelsBuilder( + int index) { + return getChannelsFieldBuilder().getBuilder(index); + } + public com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannelOrBuilder getChannelsOrBuilder( + int index) { + if (channelsBuilder_ == null) { + return channels_.get(index); } else { + return channelsBuilder_.getMessageOrBuilder(index); + } + } + public java.util.List + getChannelsOrBuilderList() { + if (channelsBuilder_ != null) { + return channelsBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(channels_); + } + } + public com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.Builder addChannelsBuilder() { + return getChannelsFieldBuilder().addBuilder( + com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.getDefaultInstance()); + } + public com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.Builder addChannelsBuilder( + int index) { + return getChannelsFieldBuilder().addBuilder( + index, com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.getDefaultInstance()); + } + public java.util.List + getChannelsBuilderList() { + return getChannelsFieldBuilder().getBuilderList(); + } + private com.google.protobuf.RepeatedFieldBuilder< + com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel, com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.Builder, com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannelOrBuilder> + getChannelsFieldBuilder() { + if (channelsBuilder_ == null) { + channelsBuilder_ = new com.google.protobuf.RepeatedFieldBuilder< + com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel, com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.Builder, com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannelOrBuilder>( + channels_, + ((bitField0_ & 0x00000001) == 0x00000001), + getParentForChildren(), + isClean()); + channels_ = null; + } + return channelsBuilder_; + } + + // @@protoc_insertion_point(builder_scope:paymentchannels.StoredServerPaymentChannels) + } + + static { + defaultInstance = new StoredServerPaymentChannels(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:paymentchannels.StoredServerPaymentChannels) + } + + public interface StoredServerPaymentChannelOrBuilder + extends com.google.protobuf.MessageOrBuilder { + + // required uint64 bestValueToMe = 1; + boolean hasBestValueToMe(); + long getBestValueToMe(); + + // optional bytes bestValueSignature = 2; + boolean hasBestValueSignature(); + com.google.protobuf.ByteString getBestValueSignature(); + + // required uint64 refundTransactionUnlockTimeSecs = 3; + boolean hasRefundTransactionUnlockTimeSecs(); + long getRefundTransactionUnlockTimeSecs(); + + // required bytes contractTransaction = 4; + boolean hasContractTransaction(); + com.google.protobuf.ByteString getContractTransaction(); + + // required bytes clientOutput = 5; + boolean hasClientOutput(); + com.google.protobuf.ByteString getClientOutput(); + + // required bytes myKey = 6; + boolean hasMyKey(); + com.google.protobuf.ByteString getMyKey(); + } + public static final class StoredServerPaymentChannel extends + com.google.protobuf.GeneratedMessage + implements StoredServerPaymentChannelOrBuilder { + // Use StoredServerPaymentChannel.newBuilder() to construct. + private StoredServerPaymentChannel(Builder builder) { + super(builder); + } + private StoredServerPaymentChannel(boolean noInit) {} + + private static final StoredServerPaymentChannel defaultInstance; + public static StoredServerPaymentChannel getDefaultInstance() { + return defaultInstance; + } + + public StoredServerPaymentChannel getDefaultInstanceForType() { + return defaultInstance; + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.google.bitcoin.protocols.channels.ServerState.internal_static_paymentchannels_StoredServerPaymentChannel_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.bitcoin.protocols.channels.ServerState.internal_static_paymentchannels_StoredServerPaymentChannel_fieldAccessorTable; + } + + private int bitField0_; + // required uint64 bestValueToMe = 1; + public static final int BESTVALUETOME_FIELD_NUMBER = 1; + private long bestValueToMe_; + public boolean hasBestValueToMe() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public long getBestValueToMe() { + return bestValueToMe_; + } + + // optional bytes bestValueSignature = 2; + public static final int BESTVALUESIGNATURE_FIELD_NUMBER = 2; + private com.google.protobuf.ByteString bestValueSignature_; + public boolean hasBestValueSignature() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + public com.google.protobuf.ByteString getBestValueSignature() { + return bestValueSignature_; + } + + // required uint64 refundTransactionUnlockTimeSecs = 3; + public static final int REFUNDTRANSACTIONUNLOCKTIMESECS_FIELD_NUMBER = 3; + private long refundTransactionUnlockTimeSecs_; + public boolean hasRefundTransactionUnlockTimeSecs() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + public long getRefundTransactionUnlockTimeSecs() { + return refundTransactionUnlockTimeSecs_; + } + + // required bytes contractTransaction = 4; + public static final int CONTRACTTRANSACTION_FIELD_NUMBER = 4; + private com.google.protobuf.ByteString contractTransaction_; + public boolean hasContractTransaction() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + public com.google.protobuf.ByteString getContractTransaction() { + return contractTransaction_; + } + + // required bytes clientOutput = 5; + public static final int CLIENTOUTPUT_FIELD_NUMBER = 5; + private com.google.protobuf.ByteString clientOutput_; + public boolean hasClientOutput() { + return ((bitField0_ & 0x00000010) == 0x00000010); + } + public com.google.protobuf.ByteString getClientOutput() { + return clientOutput_; + } + + // required bytes myKey = 6; + public static final int MYKEY_FIELD_NUMBER = 6; + private com.google.protobuf.ByteString myKey_; + public boolean hasMyKey() { + return ((bitField0_ & 0x00000020) == 0x00000020); + } + public com.google.protobuf.ByteString getMyKey() { + return myKey_; + } + + private void initFields() { + bestValueToMe_ = 0L; + bestValueSignature_ = com.google.protobuf.ByteString.EMPTY; + refundTransactionUnlockTimeSecs_ = 0L; + contractTransaction_ = com.google.protobuf.ByteString.EMPTY; + clientOutput_ = com.google.protobuf.ByteString.EMPTY; + myKey_ = com.google.protobuf.ByteString.EMPTY; + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized != -1) return isInitialized == 1; + + if (!hasBestValueToMe()) { + memoizedIsInitialized = 0; + return false; + } + if (!hasRefundTransactionUnlockTimeSecs()) { + memoizedIsInitialized = 0; + return false; + } + if (!hasContractTransaction()) { + memoizedIsInitialized = 0; + return false; + } + if (!hasClientOutput()) { + memoizedIsInitialized = 0; + return false; + } + if (!hasMyKey()) { + memoizedIsInitialized = 0; + return false; + } + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeUInt64(1, bestValueToMe_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeBytes(2, bestValueSignature_); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + output.writeUInt64(3, refundTransactionUnlockTimeSecs_); + } + if (((bitField0_ & 0x00000008) == 0x00000008)) { + output.writeBytes(4, contractTransaction_); + } + if (((bitField0_ & 0x00000010) == 0x00000010)) { + output.writeBytes(5, clientOutput_); + } + if (((bitField0_ & 0x00000020) == 0x00000020)) { + output.writeBytes(6, myKey_); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.CodedOutputStream + .computeUInt64Size(1, bestValueToMe_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(2, bestValueSignature_); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + size += com.google.protobuf.CodedOutputStream + .computeUInt64Size(3, refundTransactionUnlockTimeSecs_); + } + if (((bitField0_ & 0x00000008) == 0x00000008)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(4, contractTransaction_); + } + if (((bitField0_ & 0x00000010) == 0x00000010)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(5, clientOutput_); + } + if (((bitField0_ & 0x00000020) == 0x00000020)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(6, myKey_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + @java.lang.Override + protected java.lang.Object writeReplace() + throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel parseFrom(java.io.InputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input, extensionRegistry)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder + implements com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannelOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.google.bitcoin.protocols.channels.ServerState.internal_static_paymentchannels_StoredServerPaymentChannel_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.bitcoin.protocols.channels.ServerState.internal_static_paymentchannels_StoredServerPaymentChannel_fieldAccessorTable; + } + + // Construct using com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + bestValueToMe_ = 0L; + bitField0_ = (bitField0_ & ~0x00000001); + bestValueSignature_ = com.google.protobuf.ByteString.EMPTY; + bitField0_ = (bitField0_ & ~0x00000002); + refundTransactionUnlockTimeSecs_ = 0L; + bitField0_ = (bitField0_ & ~0x00000004); + contractTransaction_ = com.google.protobuf.ByteString.EMPTY; + bitField0_ = (bitField0_ & ~0x00000008); + clientOutput_ = com.google.protobuf.ByteString.EMPTY; + bitField0_ = (bitField0_ & ~0x00000010); + myKey_ = com.google.protobuf.ByteString.EMPTY; + bitField0_ = (bitField0_ & ~0x00000020); + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.getDescriptor(); + } + + public com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel getDefaultInstanceForType() { + return com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.getDefaultInstance(); + } + + public com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel build() { + com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + private com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel buildParsed() + throws com.google.protobuf.InvalidProtocolBufferException { + com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException( + result).asInvalidProtocolBufferException(); + } + return result; + } + + public com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel buildPartial() { + com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel result = new com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.bestValueToMe_ = bestValueToMe_; + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; + } + result.bestValueSignature_ = bestValueSignature_; + if (((from_bitField0_ & 0x00000004) == 0x00000004)) { + to_bitField0_ |= 0x00000004; + } + result.refundTransactionUnlockTimeSecs_ = refundTransactionUnlockTimeSecs_; + if (((from_bitField0_ & 0x00000008) == 0x00000008)) { + to_bitField0_ |= 0x00000008; + } + result.contractTransaction_ = contractTransaction_; + if (((from_bitField0_ & 0x00000010) == 0x00000010)) { + to_bitField0_ |= 0x00000010; + } + result.clientOutput_ = clientOutput_; + if (((from_bitField0_ & 0x00000020) == 0x00000020)) { + to_bitField0_ |= 0x00000020; + } + result.myKey_ = myKey_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel) { + return mergeFrom((com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel other) { + if (other == com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.getDefaultInstance()) return this; + if (other.hasBestValueToMe()) { + setBestValueToMe(other.getBestValueToMe()); + } + if (other.hasBestValueSignature()) { + setBestValueSignature(other.getBestValueSignature()); + } + if (other.hasRefundTransactionUnlockTimeSecs()) { + setRefundTransactionUnlockTimeSecs(other.getRefundTransactionUnlockTimeSecs()); + } + if (other.hasContractTransaction()) { + setContractTransaction(other.getContractTransaction()); + } + if (other.hasClientOutput()) { + setClientOutput(other.getClientOutput()); + } + if (other.hasMyKey()) { + setMyKey(other.getMyKey()); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + if (!hasBestValueToMe()) { + + return false; + } + if (!hasRefundTransactionUnlockTimeSecs()) { + + return false; + } + if (!hasContractTransaction()) { + + return false; + } + if (!hasClientOutput()) { + + return false; + } + if (!hasMyKey()) { + + return false; + } + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder( + this.getUnknownFields()); + while (true) { + int tag = input.readTag(); + switch (tag) { + case 0: + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + } + break; + } + case 8: { + bitField0_ |= 0x00000001; + bestValueToMe_ = input.readUInt64(); + break; + } + case 18: { + bitField0_ |= 0x00000002; + bestValueSignature_ = input.readBytes(); + break; + } + case 24: { + bitField0_ |= 0x00000004; + refundTransactionUnlockTimeSecs_ = input.readUInt64(); + break; + } + case 34: { + bitField0_ |= 0x00000008; + contractTransaction_ = input.readBytes(); + break; + } + case 42: { + bitField0_ |= 0x00000010; + clientOutput_ = input.readBytes(); + break; + } + case 50: { + bitField0_ |= 0x00000020; + myKey_ = input.readBytes(); + break; + } + } + } + } + + private int bitField0_; + + // required uint64 bestValueToMe = 1; + private long bestValueToMe_ ; + public boolean hasBestValueToMe() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public long getBestValueToMe() { + return bestValueToMe_; + } + public Builder setBestValueToMe(long value) { + bitField0_ |= 0x00000001; + bestValueToMe_ = value; + onChanged(); + return this; + } + public Builder clearBestValueToMe() { + bitField0_ = (bitField0_ & ~0x00000001); + bestValueToMe_ = 0L; + onChanged(); + return this; + } + + // optional bytes bestValueSignature = 2; + private com.google.protobuf.ByteString bestValueSignature_ = com.google.protobuf.ByteString.EMPTY; + public boolean hasBestValueSignature() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + public com.google.protobuf.ByteString getBestValueSignature() { + return bestValueSignature_; + } + public Builder setBestValueSignature(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000002; + bestValueSignature_ = value; + onChanged(); + return this; + } + public Builder clearBestValueSignature() { + bitField0_ = (bitField0_ & ~0x00000002); + bestValueSignature_ = getDefaultInstance().getBestValueSignature(); + onChanged(); + return this; + } + + // required uint64 refundTransactionUnlockTimeSecs = 3; + private long refundTransactionUnlockTimeSecs_ ; + public boolean hasRefundTransactionUnlockTimeSecs() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + public long getRefundTransactionUnlockTimeSecs() { + return refundTransactionUnlockTimeSecs_; + } + public Builder setRefundTransactionUnlockTimeSecs(long value) { + bitField0_ |= 0x00000004; + refundTransactionUnlockTimeSecs_ = value; + onChanged(); + return this; + } + public Builder clearRefundTransactionUnlockTimeSecs() { + bitField0_ = (bitField0_ & ~0x00000004); + refundTransactionUnlockTimeSecs_ = 0L; + onChanged(); + return this; + } + + // required bytes contractTransaction = 4; + private com.google.protobuf.ByteString contractTransaction_ = com.google.protobuf.ByteString.EMPTY; + public boolean hasContractTransaction() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + public com.google.protobuf.ByteString getContractTransaction() { + return contractTransaction_; + } + public Builder setContractTransaction(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000008; + contractTransaction_ = value; + onChanged(); + return this; + } + public Builder clearContractTransaction() { + bitField0_ = (bitField0_ & ~0x00000008); + contractTransaction_ = getDefaultInstance().getContractTransaction(); + onChanged(); + return this; + } + + // required bytes clientOutput = 5; + private com.google.protobuf.ByteString clientOutput_ = com.google.protobuf.ByteString.EMPTY; + public boolean hasClientOutput() { + return ((bitField0_ & 0x00000010) == 0x00000010); + } + public com.google.protobuf.ByteString getClientOutput() { + return clientOutput_; + } + public Builder setClientOutput(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000010; + clientOutput_ = value; + onChanged(); + return this; + } + public Builder clearClientOutput() { + bitField0_ = (bitField0_ & ~0x00000010); + clientOutput_ = getDefaultInstance().getClientOutput(); + onChanged(); + return this; + } + + // required bytes myKey = 6; + private com.google.protobuf.ByteString myKey_ = com.google.protobuf.ByteString.EMPTY; + public boolean hasMyKey() { + return ((bitField0_ & 0x00000020) == 0x00000020); + } + public com.google.protobuf.ByteString getMyKey() { + return myKey_; + } + public Builder setMyKey(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000020; + myKey_ = value; + onChanged(); + return this; + } + public Builder clearMyKey() { + bitField0_ = (bitField0_ & ~0x00000020); + myKey_ = getDefaultInstance().getMyKey(); + onChanged(); + return this; + } + + // @@protoc_insertion_point(builder_scope:paymentchannels.StoredServerPaymentChannel) + } + + static { + defaultInstance = new StoredServerPaymentChannel(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:paymentchannels.StoredServerPaymentChannel) + } + + private static com.google.protobuf.Descriptors.Descriptor + internal_static_paymentchannels_StoredServerPaymentChannels_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_paymentchannels_StoredServerPaymentChannels_fieldAccessorTable; + private static com.google.protobuf.Descriptors.Descriptor + internal_static_paymentchannels_StoredServerPaymentChannel_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_paymentchannels_StoredServerPaymentChannel_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n storedserverpaymentchannel.proto\022\017paym" + + "entchannels\"\\\n\033StoredServerPaymentChanne" + + "ls\022=\n\010channels\030\001 \003(\0132+.paymentchannels.S" + + "toredServerPaymentChannel\"\272\001\n\032StoredServ" + + "erPaymentChannel\022\025\n\rbestValueToMe\030\001 \002(\004\022" + + "\032\n\022bestValueSignature\030\002 \001(\014\022\'\n\037refundTra" + + "nsactionUnlockTimeSecs\030\003 \002(\004\022\033\n\023contract" + + "Transaction\030\004 \002(\014\022\024\n\014clientOutput\030\005 \002(\014\022" + + "\r\n\005myKey\030\006 \002(\014B4\n%com.google.bitcoin.pro" + + "tocols.channelsB\013ServerState" + }; + com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = + new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { + public com.google.protobuf.ExtensionRegistry assignDescriptors( + com.google.protobuf.Descriptors.FileDescriptor root) { + descriptor = root; + internal_static_paymentchannels_StoredServerPaymentChannels_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_paymentchannels_StoredServerPaymentChannels_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_paymentchannels_StoredServerPaymentChannels_descriptor, + new java.lang.String[] { "Channels", }, + com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels.class, + com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannels.Builder.class); + internal_static_paymentchannels_StoredServerPaymentChannel_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_paymentchannels_StoredServerPaymentChannel_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_paymentchannels_StoredServerPaymentChannel_descriptor, + new java.lang.String[] { "BestValueToMe", "BestValueSignature", "RefundTransactionUnlockTimeSecs", "ContractTransaction", "ClientOutput", "MyKey", }, + com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.class, + com.google.bitcoin.protocols.channels.ServerState.StoredServerPaymentChannel.Builder.class); + return null; + } + }; + com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }, assigner); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelClientStates.java b/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelClientStates.java index a631b00f..bc015139 100644 --- a/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelClientStates.java +++ b/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelClientStates.java @@ -28,6 +28,7 @@ import com.google.bitcoin.core.*; import com.google.bitcoin.utils.Threading; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.HashMultimap; +import com.google.protobuf.ByteString; import net.jcip.annotations.GuardedBy; import static com.google.common.base.Preconditions.checkNotNull; @@ -157,14 +158,22 @@ public class StoredPaymentChannelClientStates implements WalletExtension { public byte[] serializeWalletExtension() { lock.lock(); try { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(out); + ClientState.StoredClientPaymentChannels.Builder builder = ClientState.StoredClientPaymentChannels.newBuilder(); for (StoredClientChannel channel : mapChannels.values()) { - oos.writeObject(channel); + // First a few asserts to make sure things won't break + checkState(channel.valueToMe.compareTo(BigInteger.ZERO) >= 0 && channel.valueToMe.compareTo(NetworkParameters.MAX_MONEY) < 0); + checkState(channel.refundFees.compareTo(BigInteger.ZERO) >= 0 && channel.refundFees.compareTo(NetworkParameters.MAX_MONEY) < 0); + checkNotNull(channel.myKey.getPrivKeyBytes()); + checkState(channel.refund.getConfidence().getSource() == TransactionConfidence.Source.SELF); + builder.addChannels(ClientState.StoredClientPaymentChannel.newBuilder() + .setId(ByteString.copyFrom(channel.id.getBytes())) + .setContractTransaction(ByteString.copyFrom(channel.contract.bitcoinSerialize())) + .setRefundTransaction(ByteString.copyFrom(channel.refund.bitcoinSerialize())) + .setMyKey(ByteString.copyFrom(channel.myKey.getPrivKeyBytes())) + .setValueToMe(channel.valueToMe.longValue()) + .setRefundFees(channel.refundFees.longValue())); } - return out.toByteArray(); - } catch (IOException e) { - throw new RuntimeException(e); + return builder.build().toByteArray(); } finally { lock.unlock(); } @@ -176,10 +185,17 @@ public class StoredPaymentChannelClientStates implements WalletExtension { try { checkState(this.containingWallet == null || this.containingWallet == containingWallet); this.containingWallet = containingWallet; - ByteArrayInputStream inStream = new ByteArrayInputStream(data); - ObjectInputStream ois = new ObjectInputStream(inStream); - while (inStream.available() > 0) { - StoredClientChannel channel = (StoredClientChannel)ois.readObject(); + NetworkParameters params = containingWallet.getParams(); + ClientState.StoredClientPaymentChannels states = ClientState.StoredClientPaymentChannels.parseFrom(data); + for (ClientState.StoredClientPaymentChannel storedState : states.getChannelsList()) { + Transaction refundTransaction = new Transaction(params, storedState.getRefundTransaction().toByteArray()); + refundTransaction.getConfidence().setSource(TransactionConfidence.Source.SELF); + StoredClientChannel channel = new StoredClientChannel(new Sha256Hash(storedState.getId().toByteArray()), + new Transaction(params, storedState.getContractTransaction().toByteArray()), + refundTransaction, + new ECKey(storedState.getMyKey().toByteArray(), null), + BigInteger.valueOf(storedState.getValueToMe()), + BigInteger.valueOf(storedState.getRefundFees())); putChannel(channel, false); } } finally { @@ -193,14 +209,14 @@ public class StoredPaymentChannelClientStates implements WalletExtension { * channel which was interrupted (eg on connection failure) or keep track of refund transactions which need broadcast * when they expire. */ -class StoredClientChannel implements Serializable { +class StoredClientChannel { Sha256Hash id; Transaction contract, refund; ECKey myKey; BigInteger valueToMe, refundFees; // In-memory flag to indicate intent to resume this channel (or that the channel is already in use) - transient boolean active = false; + boolean active = false; StoredClientChannel(Sha256Hash id, Transaction contract, Transaction refund, ECKey myKey, BigInteger valueToMe, BigInteger refundFees) { this.id = id; diff --git a/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelServerStates.java b/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelServerStates.java index 14c6f5c0..f876f469 100644 --- a/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelServerStates.java +++ b/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelServerStates.java @@ -17,16 +17,19 @@ package com.google.bitcoin.protocols.channels; import java.io.*; +import java.math.BigInteger; import java.util.*; import java.util.concurrent.locks.ReentrantLock; import com.google.bitcoin.core.*; import com.google.bitcoin.utils.Threading; import com.google.common.annotations.VisibleForTesting; +import com.google.protobuf.ByteString; import net.jcip.annotations.GuardedBy; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; /** * Keeps track of a set of {@link StoredServerChannel}s and expires them 2 hours before their refund transactions @@ -142,14 +145,23 @@ public class StoredPaymentChannelServerStates implements WalletExtension { public byte[] serializeWalletExtension() { lock.lock(); try { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(out); + ServerState.StoredServerPaymentChannels.Builder builder = ServerState.StoredServerPaymentChannels.newBuilder(); for (StoredServerChannel channel : mapChannels.values()) { - oos.writeObject(channel); + // First a few asserts to make sure things won't break + checkState(channel.bestValueToMe.compareTo(BigInteger.ZERO) >= 0 && channel.bestValueToMe.compareTo(NetworkParameters.MAX_MONEY) < 0); + checkState(channel.refundTransactionUnlockTimeSecs > 0); + checkNotNull(channel.myKey.getPrivKeyBytes()); + ServerState.StoredServerPaymentChannel.Builder channelBuilder = ServerState.StoredServerPaymentChannel.newBuilder() + .setBestValueToMe(channel.bestValueToMe.longValue()) + .setRefundTransactionUnlockTimeSecs(channel.refundTransactionUnlockTimeSecs) + .setContractTransaction(ByteString.copyFrom(channel.contract.bitcoinSerialize())) + .setClientOutput(ByteString.copyFrom(channel.clientOutput.bitcoinSerialize())) + .setMyKey(ByteString.copyFrom(channel.myKey.getPrivKeyBytes())); + if (channel.bestValueSignature != null) + channelBuilder.setBestValueSignature(ByteString.copyFrom(channel.bestValueSignature)); + builder.addChannels(channelBuilder); } - return out.toByteArray(); - } catch (IOException e) { - throw new RuntimeException(e); + return builder.build().toByteArray(); } finally { lock.unlock(); } @@ -160,10 +172,16 @@ public class StoredPaymentChannelServerStates implements WalletExtension { lock.lock(); try { checkArgument(containingWallet == wallet); - ByteArrayInputStream inStream = new ByteArrayInputStream(data); - ObjectInputStream ois = new ObjectInputStream(inStream); - while (inStream.available() > 0) { - StoredServerChannel channel = (StoredServerChannel)ois.readObject(); + ServerState.StoredServerPaymentChannels states = ServerState.StoredServerPaymentChannels.parseFrom(data); + NetworkParameters params = containingWallet.getParams(); + for (ServerState.StoredServerPaymentChannel storedState : states.getChannelsList()) { + StoredServerChannel channel = new StoredServerChannel(null, + new Transaction(params, storedState.getContractTransaction().toByteArray()), + new TransactionOutput(params, null, storedState.getClientOutput().toByteArray(), 0), + storedState.getRefundTransactionUnlockTimeSecs(), + new ECKey(storedState.getMyKey().toByteArray(), null), + BigInteger.valueOf(storedState.getBestValueToMe()), + storedState.hasBestValueSignature() ? storedState.getBestValueSignature().toByteArray() : null); putChannel(channel); } } finally { diff --git a/core/src/main/java/com/google/bitcoin/protocols/channels/StoredServerChannel.java b/core/src/main/java/com/google/bitcoin/protocols/channels/StoredServerChannel.java index ca251b29..df0f404e 100644 --- a/core/src/main/java/com/google/bitcoin/protocols/channels/StoredServerChannel.java +++ b/core/src/main/java/com/google/bitcoin/protocols/channels/StoredServerChannel.java @@ -28,7 +28,7 @@ import static com.google.common.base.Preconditions.checkArgument; * channel which was interrupted (eg on connection failure) or close the channel automatically as the channel expire * time approaches. */ -public class StoredServerChannel implements Serializable { +public class StoredServerChannel { BigInteger bestValueToMe; byte[] bestValueSignature; long refundTransactionUnlockTimeSecs; @@ -38,8 +38,8 @@ public class StoredServerChannel implements Serializable { // In-memory pointer to the event handler which handles this channel if the client is connected. // Used as a flag to prevent duplicate connections and to disconnect the channel if its expire time approaches. - transient PaymentChannelServer connectedHandler = null; - transient PaymentChannelServerState state = null; + PaymentChannelServer connectedHandler = null; + PaymentChannelServerState state = null; StoredServerChannel(PaymentChannelServerState state, Transaction contract, TransactionOutput clientOutput, long refundTransactionUnlockTimeSecs, ECKey myKey, BigInteger bestValueToMe, byte[] bestValueSignature) { diff --git a/core/src/storedclientpaymentchannel.proto b/core/src/storedclientpaymentchannel.proto new file mode 100644 index 00000000..2bbbe7e4 --- /dev/null +++ b/core/src/storedclientpaymentchannel.proto @@ -0,0 +1,45 @@ +/** Copyright 2013 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Authors: Mike Hearn, Matt Corallo + */ + +/* Notes: + * - Endianness: All byte arrays that represent numbers (such as hashes and private keys) are Big Endian + * - To regenerate after editing, run mvn clean package -DupdateProtobuf + */ + +package paymentchannels; + +option java_package = "com.google.bitcoin.protocols.channels"; +option java_outer_classname = "ClientState"; + + +// A set of StoredPaymentChannel's +message StoredClientPaymentChannels { + repeated StoredClientPaymentChannel channels = 1; +} + +// A client-side payment channel in serialized form, which can be reloaded later if the client restarts and wants to +// reopen an existing channel +message StoredClientPaymentChannel { + required bytes id = 1; + required bytes contractTransaction = 2; + required bytes refundTransaction = 3; + required bytes myKey = 4; + required uint64 valueToMe = 5; + required uint64 refundFees = 6; +} \ No newline at end of file diff --git a/core/src/storedserverpaymentchannel.proto b/core/src/storedserverpaymentchannel.proto new file mode 100644 index 00000000..96a9106e --- /dev/null +++ b/core/src/storedserverpaymentchannel.proto @@ -0,0 +1,44 @@ +/** Copyright 2013 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Authors: Mike Hearn, Matt Corallo + */ + +/* Notes: + * - Endianness: All byte arrays that represent numbers (such as hashes and private keys) are Big Endian + * - To regenerate after editing, run mvn clean package -DupdateProtobuf + */ + +package paymentchannels; + +option java_package = "com.google.bitcoin.protocols.channels"; +option java_outer_classname = "ServerState"; + + +// A set of StoredPaymentChannel's +message StoredServerPaymentChannels { + repeated StoredServerPaymentChannel channels = 1; +} + +// A server-side payment channel in serialized form, which can be reloaded later if the server restarts +message StoredServerPaymentChannel { + required uint64 bestValueToMe = 1; + optional bytes bestValueSignature = 2; + required uint64 refundTransactionUnlockTimeSecs = 3; + required bytes contractTransaction = 4; + required bytes clientOutput = 5; + required bytes myKey = 6; +} \ No newline at end of file