You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.5 KiB

  1. package loopdb
  2. import (
  3. "math"
  4. "github.com/lightninglabs/loop/looprpc"
  5. )
  6. // ProtocolVersion represents the protocol version (declared on rpc level) that
  7. // the client declared to us.
  8. type ProtocolVersion uint32
  9. const (
  10. // ProtocolVersionLegacy indicates that the client is a legacy version
  11. // that did not report its protocol version.
  12. ProtocolVersionLegacy ProtocolVersion = 0
  13. // ProtocolVersionMultiLoopOut indicates that the client supports multi
  14. // loop out.
  15. ProtocolVersionMultiLoopOut ProtocolVersion = 1
  16. // ProtocolVersionSegwitLoopIn indicates that the client supports segwit
  17. // loop in.
  18. ProtocolVersionSegwitLoopIn ProtocolVersion = 2
  19. // ProtocolVersionPreimagePush indicates that the client will push loop
  20. // out preimages to the sever to speed up claim.
  21. ProtocolVersionPreimagePush ProtocolVersion = 3
  22. // ProtocolVersionUserExpiryLoopOut indicates that the client will
  23. // propose a cltv expiry height for loop out.
  24. ProtocolVersionUserExpiryLoopOut ProtocolVersion = 4
  25. // ProtocolVersionHtlcV2 indicates that the client will use the new
  26. // HTLC v2 scrips for swaps.
  27. ProtocolVersionHtlcV2 ProtocolVersion = 5
  28. // ProtocolVersionMultiLoopIn indicates that the client creates a probe
  29. // invoice so that the server can perform a multi-path probe.
  30. ProtocolVersionMultiLoopIn ProtocolVersion = 6
  31. // ProtocolVersionUnrecorded is set for swaps were created before we
  32. // started saving protocol version with swaps.
  33. ProtocolVersionUnrecorded ProtocolVersion = math.MaxUint32
  34. // CurrentRPCProtocolVersion defines the version of the RPC protocol
  35. // that is currently supported by the loop client.
  36. CurrentRPCProtocolVersion = looprpc.ProtocolVersion_MULTI_LOOP_IN
  37. // CurrentInternalProtocolVersion defines the RPC current protocol in
  38. // the internal representation.
  39. CurrentInternalProtocolVersion = ProtocolVersion(CurrentRPCProtocolVersion)
  40. )
  41. // Valid returns true if the value of the ProtocolVersion is valid.
  42. func (p ProtocolVersion) Valid() bool {
  43. return p <= CurrentInternalProtocolVersion
  44. }
  45. // String returns the string representation of a protocol version.
  46. func (p ProtocolVersion) String() string {
  47. switch p {
  48. case ProtocolVersionUnrecorded:
  49. return "Unrecorded"
  50. case ProtocolVersionLegacy:
  51. return "Legacy"
  52. case ProtocolVersionMultiLoopOut:
  53. return "Multi Loop Out"
  54. case ProtocolVersionSegwitLoopIn:
  55. return "Segwit Loop In"
  56. case ProtocolVersionPreimagePush:
  57. return "Preimage Push"
  58. case ProtocolVersionUserExpiryLoopOut:
  59. return "User Expiry Loop Out"
  60. case ProtocolVersionHtlcV2:
  61. return "HTLC V2"
  62. default:
  63. return "Unknown"
  64. }
  65. }