Skip to content

Commit 10f0e3a

Browse files
author
ffranr
authored
Merge pull request #767 from lightninglabs/rfq-send-recv
A minimal version of the RFQ system
2 parents bab8f11 + 5b6872b commit 10f0e3a

34 files changed

+6367
-5
lines changed

asset/encoding.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,16 @@ func CompressedPubKeyEncoder(w io.Writer, val any, buf *[8]byte) error {
140140
return tlv.NewTypeForEncodingErr(val, "*btcec.PublicKey")
141141
}
142142

143-
func CompressedPubKeyDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error {
143+
func CompressedPubKeyDecoder(r io.Reader, val any, buf *[8]byte,
144+
l uint64) error {
145+
144146
if typ, ok := val.(**btcec.PublicKey); ok {
145147
var keyBytes [btcec.PubKeyBytesLenCompressed]byte
146148
err := tlv.DBytes33(r, &keyBytes, buf, btcec.PubKeyBytesLenCompressed)
147149
if err != nil {
148150
return err
149151
}
152+
150153
var key *btcec.PublicKey
151154
// Handle empty key, which is not on the curve.
152155
if keyBytes == [btcec.PubKeyBytesLenCompressed]byte{} {
@@ -160,6 +163,7 @@ func CompressedPubKeyDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error
160163
*typ = key
161164
return nil
162165
}
166+
163167
return tlv.NewTypeForDecodingErr(
164168
val, "*btcec.PublicKey", l, btcec.PubKeyBytesLenCompressed,
165169
)

chain_bridge.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/btcsuite/btcd/chaincfg/chainhash"
88
"github.com/btcsuite/btcd/wire"
99
"github.com/lightninglabs/lndclient"
10+
"github.com/lightninglabs/taproot-assets/rfq"
1011
"github.com/lightninglabs/taproot-assets/tapgarden"
1112
"github.com/lightningnetwork/lnd/chainntnfs"
1213
"github.com/lightningnetwork/lnd/lnrpc/verrpc"
@@ -203,3 +204,61 @@ func (l *LndRpcChainBridge) EstimateFee(ctx context.Context,
203204
// A compile time assertion to ensure LndRpcChainBridge meets the
204205
// tapgarden.ChainBridge interface.
205206
var _ tapgarden.ChainBridge = (*LndRpcChainBridge)(nil)
207+
208+
// LndMsgTransportClient is an LND RPC message transport client.
209+
type LndMsgTransportClient struct {
210+
lnd *lndclient.LndServices
211+
}
212+
213+
// NewLndMsgTransportClient creates a new message transport RPC client for a
214+
// given LND service.
215+
func NewLndMsgTransportClient(
216+
lnd *lndclient.LndServices) *LndMsgTransportClient {
217+
218+
return &LndMsgTransportClient{
219+
lnd: lnd,
220+
}
221+
}
222+
223+
// SubscribeCustomMessages creates a subscription to custom messages received
224+
// from our peers.
225+
func (l *LndMsgTransportClient) SubscribeCustomMessages(
226+
ctx context.Context) (<-chan lndclient.CustomMessage,
227+
<-chan error, error) {
228+
229+
return l.lnd.Client.SubscribeCustomMessages(ctx)
230+
}
231+
232+
// SendCustomMessage sends a custom message to a peer.
233+
func (l *LndMsgTransportClient) SendCustomMessage(ctx context.Context,
234+
msg lndclient.CustomMessage) error {
235+
236+
return l.lnd.Client.SendCustomMessage(ctx, msg)
237+
}
238+
239+
// Ensure LndMsgTransportClient implements the rfq.PeerMessenger interface.
240+
var _ rfq.PeerMessenger = (*LndMsgTransportClient)(nil)
241+
242+
// LndRouterClient is an LND router RPC client.
243+
type LndRouterClient struct {
244+
lnd *lndclient.LndServices
245+
}
246+
247+
// NewLndRouterClient creates a new LND router client for a given LND service.
248+
func NewLndRouterClient(lnd *lndclient.LndServices) *LndRouterClient {
249+
return &LndRouterClient{
250+
lnd: lnd,
251+
}
252+
}
253+
254+
// InterceptHtlcs intercepts all incoming HTLCs and calls the given handler
255+
// function with the HTLC details. The handler function can then decide whether
256+
// to accept or reject the HTLC.
257+
func (l *LndRouterClient) InterceptHtlcs(
258+
ctx context.Context, handler lndclient.HtlcInterceptHandler) error {
259+
260+
return l.lnd.Router.InterceptHtlcs(ctx, handler)
261+
}
262+
263+
// Ensure LndRouterClient implements the rfq.HtlcInterceptor interface.
264+
var _ rfq.HtlcInterceptor = (*LndRouterClient)(nil)

config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/lightninglabs/taproot-assets/address"
1111
"github.com/lightninglabs/taproot-assets/monitoring"
1212
"github.com/lightninglabs/taproot-assets/proof"
13+
"github.com/lightninglabs/taproot-assets/rfq"
1314
"github.com/lightninglabs/taproot-assets/tapdb"
1415
"github.com/lightninglabs/taproot-assets/tapfreighter"
1516
"github.com/lightninglabs/taproot-assets/tapgarden"
@@ -122,6 +123,8 @@ type Config struct {
122123

123124
UniverseFederation *universe.FederationEnvoy
124125

126+
RfqManager *rfq.Manager
127+
125128
UniverseStats universe.Telemetry
126129

127130
// UniversePublicAccess is flag which, If true, and the Universe server

itest/interface.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/lightninglabs/taproot-assets/taprpc"
55
"github.com/lightninglabs/taproot-assets/taprpc/assetwalletrpc"
66
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
7+
"github.com/lightninglabs/taproot-assets/taprpc/rfqrpc"
78
unirpc "github.com/lightninglabs/taproot-assets/taprpc/universerpc"
89
)
910

@@ -12,5 +13,6 @@ type TapdClient interface {
1213
taprpc.TaprootAssetsClient
1314
unirpc.UniverseClient
1415
mintrpc.MintClient
16+
rfqrpc.RfqClient
1517
assetwalletrpc.AssetWalletClient
1618
}

itest/loadtest/utils.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/lightninglabs/taproot-assets/taprpc"
1818
"github.com/lightninglabs/taproot-assets/taprpc/assetwalletrpc"
1919
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
20+
"github.com/lightninglabs/taproot-assets/taprpc/rfqrpc"
2021
"github.com/lightninglabs/taproot-assets/taprpc/tapdevrpc"
2122
"github.com/lightninglabs/taproot-assets/taprpc/universerpc"
2223
"github.com/lightningnetwork/lnd/macaroons"
@@ -38,6 +39,7 @@ type rpcClient struct {
3839
assetwalletrpc.AssetWalletClient
3940
tapdevrpc.TapDevClient
4041
mintrpc.MintClient
42+
rfqrpc.RfqClient
4143
universerpc.UniverseClient
4244
}
4345

@@ -171,6 +173,7 @@ func getTapClient(t *testing.T, ctx context.Context,
171173
assetWalletClient := assetwalletrpc.NewAssetWalletClient(conn)
172174
devClient := tapdevrpc.NewTapDevClient(conn)
173175
mintMintClient := mintrpc.NewMintClient(conn)
176+
rfqClient := rfqrpc.NewRfqClient(conn)
174177
universeClient := universerpc.NewUniverseClient(conn)
175178

176179
client := &rpcClient{
@@ -179,6 +182,7 @@ func getTapClient(t *testing.T, ctx context.Context,
179182
AssetWalletClient: assetWalletClient,
180183
TapDevClient: devClient,
181184
MintClient: mintMintClient,
185+
RfqClient: rfqClient,
182186
UniverseClient: universeClient,
183187
}
184188

0 commit comments

Comments
 (0)