loop/loopdb/protocol_version.go
carla dad103530f
multi: move server proto files to their own directory
Protobuf does not allow naming conflicts for files within the same
process, because all proto messages register themselves in a global
registry.

This is problematic because the server's itests import the client's
looprpc package to make rpc queries to the loopd client, thus importing
duplicate common.proto and server.proto from the client's looprc package
(since they're both in there as well).

This change moves the server's proto files into their own directory so
that they are not imported when we want to use the client's files. We
cannot change the package name for the server, because that would be
a breaking change (the package name is included in URIS). Fortunately,
we have the go_package option which allows us to place generated files
in a different location.
2021-12-13 13:56:40 +02:00

101 lines
3 KiB
Go

package loopdb
import (
"math"
"github.com/lightninglabs/loop/swapserverrpc"
)
// ProtocolVersion represents the protocol version (declared on rpc level) that
// the client declared to us.
type ProtocolVersion uint32
const (
// ProtocolVersionLegacy indicates that the client is a legacy version
// that did not report its protocol version.
ProtocolVersionLegacy ProtocolVersion = 0
// ProtocolVersionMultiLoopOut indicates that the client supports multi
// loop out.
ProtocolVersionMultiLoopOut ProtocolVersion = 1
// ProtocolVersionSegwitLoopIn indicates that the client supports segwit
// loop in.
ProtocolVersionSegwitLoopIn ProtocolVersion = 2
// ProtocolVersionPreimagePush indicates that the client will push loop
// out preimages to the sever to speed up claim.
ProtocolVersionPreimagePush ProtocolVersion = 3
// ProtocolVersionUserExpiryLoopOut indicates that the client will
// propose a cltv expiry height for loop out.
ProtocolVersionUserExpiryLoopOut ProtocolVersion = 4
// ProtocolVersionHtlcV2 indicates that the client will use the new
// HTLC v2 scrips for swaps.
ProtocolVersionHtlcV2 ProtocolVersion = 5
// ProtocolVersionMultiLoopIn indicates that the client creates a probe
// invoice so that the server can perform a multi-path probe.
ProtocolVersionMultiLoopIn ProtocolVersion = 6
// ProtocolVersionLoopOutCancel indicates that the client supports
// canceling loop out swaps.
ProtocolVersionLoopOutCancel = 7
// ProtocolVerionProbe indicates that the client is able to request
// the server to perform a probe to test inbound liquidty.
ProtocolVersionProbe ProtocolVersion = 8
// ProtocolVersionUnrecorded is set for swaps were created before we
// started saving protocol version with swaps.
ProtocolVersionUnrecorded ProtocolVersion = math.MaxUint32
// CurrentRPCProtocolVersion defines the version of the RPC protocol
// that is currently supported by the loop client.
CurrentRPCProtocolVersion = swapserverrpc.ProtocolVersion_PROBE
// CurrentInternalProtocolVersion defines the RPC current protocol in
// the internal representation.
CurrentInternalProtocolVersion = ProtocolVersion(CurrentRPCProtocolVersion)
)
// Valid returns true if the value of the ProtocolVersion is valid.
func (p ProtocolVersion) Valid() bool {
return p <= CurrentInternalProtocolVersion
}
// String returns the string representation of a protocol version.
func (p ProtocolVersion) String() string {
switch p {
case ProtocolVersionUnrecorded:
return "Unrecorded"
case ProtocolVersionLegacy:
return "Legacy"
case ProtocolVersionMultiLoopOut:
return "Multi Loop Out"
case ProtocolVersionSegwitLoopIn:
return "Segwit Loop In"
case ProtocolVersionPreimagePush:
return "Preimage Push"
case ProtocolVersionUserExpiryLoopOut:
return "User Expiry Loop Out"
case ProtocolVersionHtlcV2:
return "HTLC V2"
case ProtocolVersionLoopOutCancel:
return "Loop Out Cancel"
case ProtocolVersionProbe:
return "Probe"
default:
return "Unknown"
}
}