From e179153420fa49009c5d951ed20cb6ab3a053a97 Mon Sep 17 00:00:00 2001 From: Francisco Gindre Date: Wed, 27 Apr 2022 16:19:25 -0300 Subject: [PATCH] update protobuf files from lightwalletd's commit `68789356fb1a75f62735a529b38389ef08ea7582` --- .../Service/ProtoBuf/compact_formats.pb.swift | 103 ++++++++++++++++-- .../ProtoBuf/proto/compact_formats.proto | 22 +++- .../Service/ProtoBuf/proto/service.proto | 7 +- .../Service/ProtoBuf/service.grpc.swift | 27 +++++ .../Service/ProtoBuf/service.pb.swift | 3 +- 5 files changed, 142 insertions(+), 20 deletions(-) diff --git a/Sources/ZcashLightClientKit/Service/ProtoBuf/compact_formats.pb.swift b/Sources/ZcashLightClientKit/Service/ProtoBuf/compact_formats.pb.swift index 8897fd3b..86bb2b07 100644 --- a/Sources/ZcashLightClientKit/Service/ProtoBuf/compact_formats.pb.swift +++ b/Sources/ZcashLightClientKit/Service/ProtoBuf/compact_formats.pb.swift @@ -81,19 +81,21 @@ struct CompactTx { var fee: UInt32 = 0 /// inputs - var spends: [CompactSpend] = [] + var spends: [CompactSaplingSpend] = [] /// outputs - var outputs: [CompactOutput] = [] + var outputs: [CompactSaplingOutput] = [] + + var actions: [CompactOrchardAction] = [] var unknownFields = SwiftProtobuf.UnknownStorage() init() {} } -/// CompactSpend is a Sapling Spend Description as described in 7.3 of the Zcash +/// CompactSaplingSpend is a Sapling Spend Description as described in 7.3 of the Zcash /// protocol specification. -struct CompactSpend { +struct CompactSaplingSpend { // SwiftProtobuf.Message conformance is added in an extension below. See the // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. @@ -108,7 +110,7 @@ struct CompactSpend { /// output is a Sapling Output Description as described in section 7.4 of the /// Zcash protocol spec. Total size is 948. -struct CompactOutput { +struct CompactSaplingOutput { // SwiftProtobuf.Message conformance is added in an extension below. See the // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. @@ -119,7 +121,31 @@ struct CompactOutput { /// ephemeral public key var epk: Data = SwiftProtobuf.Internal.emptyData - /// ciphertext and zkproof + /// first 52 bytes of ciphertext + var ciphertext: Data = SwiftProtobuf.Internal.emptyData + + var unknownFields = SwiftProtobuf.UnknownStorage() + + init() {} +} + +/// https://github.com/zcash/zips/blob/main/zip-0225.rst#orchard-action-description-orchardaction +/// (but not all fields are needed) +struct CompactOrchardAction { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// [32] The nullifier of the input note + var nullifier: Data = SwiftProtobuf.Internal.emptyData + + /// [32] The x-coordinate of the note commitment for the output note + var cmx: Data = SwiftProtobuf.Internal.emptyData + + /// [32] An encoding of an ephemeral Pallas public key + var ephemeralKey: Data = SwiftProtobuf.Internal.emptyData + + /// [52] The note plaintext component of the encCiphertext field var ciphertext: Data = SwiftProtobuf.Internal.emptyData var unknownFields = SwiftProtobuf.UnknownStorage() @@ -204,6 +230,7 @@ extension CompactTx: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementation 3: .same(proto: "fee"), 4: .same(proto: "spends"), 5: .same(proto: "outputs"), + 6: .same(proto: "actions"), ] mutating func decodeMessage(decoder: inout D) throws { @@ -214,6 +241,7 @@ extension CompactTx: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementation case 3: try decoder.decodeSingularUInt32Field(value: &self.fee) case 4: try decoder.decodeRepeatedMessageField(value: &self.spends) case 5: try decoder.decodeRepeatedMessageField(value: &self.outputs) + case 6: try decoder.decodeRepeatedMessageField(value: &self.actions) default: break } } @@ -235,6 +263,9 @@ extension CompactTx: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementation if !self.outputs.isEmpty { try visitor.visitRepeatedMessageField(value: self.outputs, fieldNumber: 5) } + if !self.actions.isEmpty { + try visitor.visitRepeatedMessageField(value: self.actions, fieldNumber: 6) + } try unknownFields.traverse(visitor: &visitor) } @@ -244,13 +275,14 @@ extension CompactTx: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementation if lhs.fee != rhs.fee {return false} if lhs.spends != rhs.spends {return false} if lhs.outputs != rhs.outputs {return false} + if lhs.actions != rhs.actions {return false} if lhs.unknownFields != rhs.unknownFields {return false} return true } } -extension CompactSpend: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = _protobuf_package + ".CompactSpend" +extension CompactSaplingSpend: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + static let protoMessageName: String = _protobuf_package + ".CompactSaplingSpend" static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ 1: .same(proto: "nf"), ] @@ -271,15 +303,15 @@ extension CompactSpend: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementat try unknownFields.traverse(visitor: &visitor) } - static func ==(lhs: CompactSpend, rhs: CompactSpend) -> Bool { + static func ==(lhs: CompactSaplingSpend, rhs: CompactSaplingSpend) -> Bool { if lhs.nf != rhs.nf {return false} if lhs.unknownFields != rhs.unknownFields {return false} return true } } -extension CompactOutput: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = _protobuf_package + ".CompactOutput" +extension CompactSaplingOutput: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + static let protoMessageName: String = _protobuf_package + ".CompactSaplingOutput" static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ 1: .same(proto: "cmu"), 2: .same(proto: "epk"), @@ -310,7 +342,7 @@ extension CompactOutput: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementa try unknownFields.traverse(visitor: &visitor) } - static func ==(lhs: CompactOutput, rhs: CompactOutput) -> Bool { + static func ==(lhs: CompactSaplingOutput, rhs: CompactSaplingOutput) -> Bool { if lhs.cmu != rhs.cmu {return false} if lhs.epk != rhs.epk {return false} if lhs.ciphertext != rhs.ciphertext {return false} @@ -318,3 +350,50 @@ extension CompactOutput: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementa return true } } + +extension CompactOrchardAction: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + static let protoMessageName: String = _protobuf_package + ".CompactOrchardAction" + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "nullifier"), + 2: .same(proto: "cmx"), + 3: .same(proto: "ephemeralKey"), + 4: .same(proto: "ciphertext"), + ] + + mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularBytesField(value: &self.nullifier) + case 2: try decoder.decodeSingularBytesField(value: &self.cmx) + case 3: try decoder.decodeSingularBytesField(value: &self.ephemeralKey) + case 4: try decoder.decodeSingularBytesField(value: &self.ciphertext) + default: break + } + } + } + + func traverse(visitor: inout V) throws { + if !self.nullifier.isEmpty { + try visitor.visitSingularBytesField(value: self.nullifier, fieldNumber: 1) + } + if !self.cmx.isEmpty { + try visitor.visitSingularBytesField(value: self.cmx, fieldNumber: 2) + } + if !self.ephemeralKey.isEmpty { + try visitor.visitSingularBytesField(value: self.ephemeralKey, fieldNumber: 3) + } + if !self.ciphertext.isEmpty { + try visitor.visitSingularBytesField(value: self.ciphertext, fieldNumber: 4) + } + try unknownFields.traverse(visitor: &visitor) + } + + static func ==(lhs: CompactOrchardAction, rhs: CompactOrchardAction) -> Bool { + if lhs.nullifier != rhs.nullifier {return false} + if lhs.cmx != rhs.cmx {return false} + if lhs.ephemeralKey != rhs.ephemeralKey {return false} + if lhs.ciphertext != rhs.ciphertext {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/ZcashLightClientKit/Service/ProtoBuf/proto/compact_formats.proto b/Sources/ZcashLightClientKit/Service/ProtoBuf/proto/compact_formats.proto index bf51ebb3..f2129f2c 100644 --- a/Sources/ZcashLightClientKit/Service/ProtoBuf/proto/compact_formats.proto +++ b/Sources/ZcashLightClientKit/Service/ProtoBuf/proto/compact_formats.proto @@ -37,20 +37,30 @@ message CompactTx { // valueBalance + (sum(vPubNew) - sum(vPubOld) - sum(tOut)) uint32 fee = 3; - repeated CompactSpend spends = 4; // inputs - repeated CompactOutput outputs = 5; // outputs + repeated CompactSaplingSpend spends = 4; // inputs + repeated CompactSaplingOutput outputs = 5; // outputs + repeated CompactOrchardAction actions = 6; } -// CompactSpend is a Sapling Spend Description as described in 7.3 of the Zcash +// CompactSaplingSpend is a Sapling Spend Description as described in 7.3 of the Zcash // protocol specification. -message CompactSpend { +message CompactSaplingSpend { bytes nf = 1; // nullifier (see the Zcash protocol specification) } // output is a Sapling Output Description as described in section 7.4 of the // Zcash protocol spec. Total size is 948. -message CompactOutput { +message CompactSaplingOutput { bytes cmu = 1; // note commitment u-coordinate bytes epk = 2; // ephemeral public key - bytes ciphertext = 3; // ciphertext and zkproof + bytes ciphertext = 3; // first 52 bytes of ciphertext +} + +// https://github.com/zcash/zips/blob/main/zip-0225.rst#orchard-action-description-orchardaction +// (but not all fields are needed) +message CompactOrchardAction { + bytes nullifier = 1; // [32] The nullifier of the input note + bytes cmx = 2; // [32] The x-coordinate of the note commitment for the output note + bytes ephemeralKey = 3; // [32] An encoding of an ephemeral Pallas public key + bytes ciphertext = 4; // [52] The note plaintext component of the encCiphertext field } diff --git a/Sources/ZcashLightClientKit/Service/ProtoBuf/proto/service.proto b/Sources/ZcashLightClientKit/Service/ProtoBuf/proto/service.proto index 8021e3fa..91d0ada1 100644 --- a/Sources/ZcashLightClientKit/Service/ProtoBuf/proto/service.proto +++ b/Sources/ZcashLightClientKit/Service/ProtoBuf/proto/service.proto @@ -32,7 +32,8 @@ message TxFilter { } // RawTransaction contains the complete transaction data. It also optionally includes -// the block height in which the transaction was included. +// the block height in which the transaction was included, or, when returned +// by GetMempoolStream(), the latest block height. message RawTransaction { bytes data = 1; // exact data returned by Zcash 'getrawtransaction' uint64 height = 2; // height that the transaction was mined (or -1) @@ -164,6 +165,10 @@ service CompactTxStreamer { // in the exclude list that don't exist in the mempool are ignored. rpc GetMempoolTx(Exclude) returns (stream CompactTx) {} + // Return a stream of current Mempool transactions. This will keep the output stream open while + // there are mempool transactions. It will close the returned stream when a new block is mined. + rpc GetMempoolStream(Empty) returns (stream RawTransaction) {} + // GetTreeState returns the note commitment tree state corresponding to the given block. // See section 3.7 of the Zcash protocol specification. It returns several other useful // values also (even though they can be obtained using GetBlock). diff --git a/Sources/ZcashLightClientKit/Service/ProtoBuf/service.grpc.swift b/Sources/ZcashLightClientKit/Service/ProtoBuf/service.grpc.swift index 9a1de9ae..f265da8e 100644 --- a/Sources/ZcashLightClientKit/Service/ProtoBuf/service.grpc.swift +++ b/Sources/ZcashLightClientKit/Service/ProtoBuf/service.grpc.swift @@ -74,6 +74,12 @@ internal protocol CompactTxStreamerClientProtocol: GRPCClient { handler: @escaping (CompactTx) -> Void ) -> ServerStreamingCall + func getMempoolStream( + _ request: Empty, + callOptions: CallOptions?, + handler: @escaping (RawTransaction) -> Void + ) -> ServerStreamingCall + func getTreeState( _ request: BlockID, callOptions: CallOptions? @@ -274,6 +280,27 @@ extension CompactTxStreamerClientProtocol { ) } + /// Return a stream of current Mempool transactions. This will keep the output stream open while + /// there are mempool transactions. It will close the returned stream when a new block is mined. + /// + /// - Parameters: + /// - request: Request to send to GetMempoolStream. + /// - callOptions: Call options. + /// - handler: A closure called when each response is received from the server. + /// - Returns: A `ServerStreamingCall` with futures for the metadata and status. + internal func getMempoolStream( + _ request: Empty, + callOptions: CallOptions? = nil, + handler: @escaping (RawTransaction) -> Void + ) -> ServerStreamingCall { + return self.makeServerStreamingCall( + path: "/cash.z.wallet.sdk.rpc.CompactTxStreamer/GetMempoolStream", + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + handler: handler + ) + } + /// GetTreeState returns the note commitment tree state corresponding to the given block. /// See section 3.7 of the Zcash protocol specification. It returns several other useful /// values also (even though they can be obtained using GetBlock). diff --git a/Sources/ZcashLightClientKit/Service/ProtoBuf/service.pb.swift b/Sources/ZcashLightClientKit/Service/ProtoBuf/service.pb.swift index 13e8e800..e6eb56b8 100644 --- a/Sources/ZcashLightClientKit/Service/ProtoBuf/service.pb.swift +++ b/Sources/ZcashLightClientKit/Service/ProtoBuf/service.pb.swift @@ -105,7 +105,8 @@ struct TxFilter { } /// RawTransaction contains the complete transaction data. It also optionally includes -/// the block height in which the transaction was included. +/// the block height in which the transaction was included, or, when returned +/// by GetMempoolStream(), the latest block height. struct RawTransaction { // SwiftProtobuf.Message conformance is added in an extension below. See the // `Message` and `Message+*Additions` files in the SwiftProtobuf library for