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.

94 lines
2.7 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. // ProtocolVersionLoopOutCancel indicates that the client supports
  32. // canceling loop out swaps.
  33. ProtocolVersionLoopOutCancel = 7
  34. // ProtocolVersionUnrecorded is set for swaps were created before we
  35. // started saving protocol version with swaps.
  36. ProtocolVersionUnrecorded ProtocolVersion = math.MaxUint32
  37. // CurrentRPCProtocolVersion defines the version of the RPC protocol
  38. // that is currently supported by the loop client.
  39. CurrentRPCProtocolVersion = looprpc.ProtocolVersion_LOOP_OUT_CANCEL
  40. // CurrentInternalProtocolVersion defines the RPC current protocol in
  41. // the internal representation.
  42. CurrentInternalProtocolVersion = ProtocolVersion(CurrentRPCProtocolVersion)
  43. )
  44. // Valid returns true if the value of the ProtocolVersion is valid.
  45. func (p ProtocolVersion) Valid() bool {
  46. return p <= CurrentInternalProtocolVersion
  47. }
  48. // String returns the string representation of a protocol version.
  49. func (p ProtocolVersion) String() string {
  50. switch p {
  51. case ProtocolVersionUnrecorded:
  52. return "Unrecorded"
  53. case ProtocolVersionLegacy:
  54. return "Legacy"
  55. case ProtocolVersionMultiLoopOut:
  56. return "Multi Loop Out"
  57. case ProtocolVersionSegwitLoopIn:
  58. return "Segwit Loop In"
  59. case ProtocolVersionPreimagePush:
  60. return "Preimage Push"
  61. case ProtocolVersionUserExpiryLoopOut:
  62. return "User Expiry Loop Out"
  63. case ProtocolVersionHtlcV2:
  64. return "HTLC V2"
  65. case ProtocolVersionLoopOutCancel:
  66. return "Loop Out Cancel"
  67. default:
  68. return "Unknown"
  69. }
  70. }