Skip to content

Commit

Permalink
Added xsn support for swap-resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
RostyslavAntonyshyn committed Oct 10, 2018
1 parent 364a629 commit 038f39f
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 14 deletions.
8 changes: 6 additions & 2 deletions cmd/resolver-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ func takeOrder(ctx *cli.Context) error{
req.MakerCoin = pb.CoinType_BTC
case "LTC":
req.MakerCoin = pb.CoinType_LTC
case "XSN":
req.MakerCoin = pb.CoinType_XSN
default:
return fmt.Errorf("Invalid maker coin %v. Valid values are BTC and LTC only.", ctx.String("maker_coin"))
return fmt.Errorf("Invalid maker coin %v. Valid values are BTC, LTC and XSN only.", ctx.String("maker_coin"))
}

if !ctx.IsSet("taker_amount"){
Expand All @@ -168,8 +170,10 @@ func takeOrder(ctx *cli.Context) error{
req.TakerCoin = pb.CoinType_BTC
case "LTC":
req.TakerCoin = pb.CoinType_LTC
case "XSN":
req.TakerCoin = pb.CoinType_XSN
default:
return fmt.Errorf("Invalid taker coin %v. Valid values are BTC and LTC only.", ctx.String("taker_coin"))
return fmt.Errorf("Invalid taker coin %v. Valid values are BTC, LTC and XSN only.", ctx.String("taker_coin"))
}

if req.MakerCoin == req.TakerCoin{
Expand Down
2 changes: 1 addition & 1 deletion exchange-a/lnd/btc/start.bash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lnd --noseedbackup --rpclisten=localhost:10002 --listen=localhost:10012 --restlisten=8002 --datadir=data --logdir=logs --nobootstrap --no-macaroons --bitcoin.active --bitcoin.testnet --btcd.rpcuser=xu --btcd.rpcpass=xu --debuglevel=debug --alias="Exchange A BTC on 10002/10012"
~/go/bin/lnd --noseedbackup --rpclisten=localhost:10002 --listen=localhost:10012 --restlisten=8002 --datadir=data --logdir=logs --nobootstrap --no-macaroons --xsncoin.active --xsncoin.testnet --xsncoin.node=xsnd --xsnd.rpcuser=ross --xsnd.rpcpass=ross --debuglevel=debug --xsnd.zmqpubrawtx=tcp://127.0.0.1:28445 --xsnd.zmqpubrawblock=tcp://127.0.0.1:28444 --alias="Exchange A BTC on 10002/10012"
3 changes: 2 additions & 1 deletion exchange-a/lnd/ltc/start.bash
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
lnd --noseedbackup --rpclisten=localhost:10001 --listen=localhost:10011 --restlisten=8001 --datadir=data --logdir=logs --nobootstrap --no-macaroons --litecoin.active --litecoin.testnet --ltcd.rpcuser=xu --ltcd.rpcpass=xu --debuglevel=debug --alias="Exchange A LTC on 10001/10011"
/tmp/lnd --noseedbackup --rpclisten=localhost:10001 --listen=localhost:10011 --restlisten=8001 --datadir=data --logdir=logs --nobootstrap --no-macaroons --litecoin.active --litecoin.testnet --litecoin.node=litecoind --litecoind.rpcuser=ross --litecoind.rpcpass=ross --litecoind.zmqpubrawblock=tcp://127.0.0.1:29332 --litecoind.zmqpubrawtx=ipc:///tmp/litecoind.tx.raw --debuglevel=debug --alias="Exchange A LTC on 10001/10011"

24 changes: 22 additions & 2 deletions exchange-a/resolver/start.bash
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
cd $GOPATH/src/github.com/ExchangeUnion/swap-resolver
go run resolver.go --listen localhost:7001 --peer localhost:7002 --lnd-rpc-ltc localhost:10001 --lnd-rpc-btc localhost:10002
if [ $# -eq 0 ]
then
echo "No arguments supplied"
fi

cd ~/go/src/github.com/ExchangeUnion/swap-resolver

case "$1" in
"btc_ltc")
go run resolver.go --listen localhost:7001 --peer localhost:7002 --lnd-rpc-ltc localhost:10001 --lnd-rpc-btc localhost:10002
;;
"btc_xsn")
go run resolver.go --listen localhost:7002 --peer localhost:7003 --lnd-rpc-btc localhost:10002 --lnd-rpc-xsn localhost:10003
;;
"ltc_xsn")
go run resolver.go --listen localhost:7001 --peer localhost:7003 --lnd-rpc-ltc localhost:10001 --lnd-rpc-xsn localhost:10003
;;
*)
echo "Wrong argument passed, supported modes to swap are: btc_ltc, btc_xsn, ltc_xsn"
exit 1
;;
esac
2 changes: 1 addition & 1 deletion exchange-b/lnd/btc/start.bash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lnd --noseedbackup --rpclisten=localhost:20002 --listen=localhost:20012 --restlisten=9002 --datadir=data --logdir=logs --nobootstrap --no-macaroons --bitcoin.active --bitcoin.testnet --btcd.rpcuser=xu --btcd.rpcpass=xu --debuglevel=debug --alias="Exchange B BTC on 20002/20012"
~/go/bin/lnd --noseedbackup --rpclisten=localhost:20002 --listen=localhost:20012 --restlisten=9002 --datadir=data --logdir=logs --nobootstrap --no-macaroons --xsncoin.active --xsncoin.testnet --xsncoin.node=xsnd --xsnd.rpcuser=ross --xsnd.rpcpass=ross --debuglevel=debug --xsnd.zmqpubrawtx=tcp://127.0.0.1:28445 --xsnd.zmqpubrawblock=tcp://127.0.0.1:28444 --alias="Exchange B BTC on 20002/20012"
2 changes: 1 addition & 1 deletion exchange-b/lnd/ltc/start.bash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lnd --noseedbackup --rpclisten=localhost:20001 --listen=localhost:20011 --restlisten=9001 --datadir=data --logdir=logs --nobootstrap --no-macaroons --litecoin.active --litecoin.testnet --ltcd.rpcuser=xu --ltcd.rpcpass=xu --debuglevel=debug --alias="Exchange B LTC on 20001/20011"
/tmp/lnd --noseedbackup --rpclisten=localhost:20001 --listen=localhost:20011 --restlisten=9001 --datadir=data --logdir=logs --nobootstrap --no-macaroons --litecoin.active --litecoin.testnet --litecoin.node=litecoind --litecoind.rpcuser=ross --litecoind.rpcpass=ross --litecoind.zmqpubrawblock=tcp://127.0.0.1:29332 --litecoind.zmqpubrawtx=ipc:///tmp/litecoind.tx.raw --debuglevel=debug --alias="Exchange B LTC on 20001/20011"
24 changes: 22 additions & 2 deletions exchange-b/resolver/start.bash
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
cd $GOPATH/src/github.com/ExchangeUnion/swap-resolver
go run resolver.go --listen localhost:7002 --peer localhost:7001 --lnd-rpc-ltc localhost:20001 --lnd-rpc-btc localhost:20002
if [ $# -eq 0 ]
then
echo "No arguments supplied"
fi

cd ~/go/src/github.com/ExchangeUnion/swap-resolver

case "$1" in
"btc_ltc")
go run resolver.go --listen localhost:7002 --peer localhost:7001 --lnd-rpc-ltc localhost:20001 --lnd-rpc-btc localhost:20002
;;
"btc_xsn")
go run resolver.go --listen localhost:7003 --peer localhost:7002 --lnd-rpc-btc localhost:20002 --lnd-rpc-xsn localhost:20003
;;
"ltc_xsn")
go run resolver.go --listen localhost:7003 --peer localhost:7001 --lnd-rpc-ltc localhost:20001 --lnd-rpc-xsn localhost:20003
;;
*)
echo "Wrong argument passed, supported modes to swap are: btc_ltc, btc_xsn, ltc_xsn"
exit 1
;;
esac
35 changes: 32 additions & 3 deletions resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ func (s *hashResolverServer) ResolveHash(ctx context.Context, req *pb.ResolveReq
switch deal.makerCoin{
case pbp2p.CoinType_BTC:

case pbp2p.CoinType_XSN:
cmdLnd = s.p2pServer.lnXSN

case pbp2p.CoinType_LTC:
cmdLnd = s.p2pServer.lnLTC

Expand Down Expand Up @@ -171,6 +174,7 @@ type P2PServer struct {
xuPeer pbp2p.P2PClient
lnLTC lnrpc.LightningClient
lnBTC lnrpc.LightningClient
lnXSN lnrpc.LightningClient
mu sync.Mutex // protects data structure
}

Expand Down Expand Up @@ -202,6 +206,12 @@ func (s *P2PServer) TakeOrder(ctx context.Context, req *pbp2p.TakeOrderReq) (*pb
return nil,fmt.Errorf("Can't getInfo from LTC LND - %v", err)
}

case pbp2p.CoinType_XSN:
info, err = s.lnXSN.GetInfo(ctxt, &lnrpc.GetInfoRequest{})
if err != nil{
return nil,fmt.Errorf("Can't getInfo from XSN LND - %v", err)
}

}
log.Printf("%v getinfo:%v",req.TakerCoin.String(),spew.Sdump(info))
spew.Sdump(info)
Expand Down Expand Up @@ -288,6 +298,13 @@ func (s *P2PServer) SuggestDeal(ctx context.Context, req *pbp2p.SuggestDealReq)
if err != nil{
return nil,fmt.Errorf("Can't getInfo from LTC LND - %v", err)
}

case pbp2p.CoinType_XSN:
info, err = s.lnXSN.GetInfo(ctxt, &lnrpc.GetInfoRequest{})
if err != nil{
return nil,fmt.Errorf("Can't getInfo from XSN LND - %v", err)
}

}
log.Printf("%v getinfo:%v",req.TakerCoin.String(),spew.Sdump(info))
spew.Sdump(info)
Expand Down Expand Up @@ -356,7 +373,10 @@ func (s *P2PServer) Swap(ctx context.Context, req *pbp2p.SwapReq) (*pbp2p.SwapRe
case pbp2p.CoinType_BTC:

case pbp2p.CoinType_LTC:
cmdLnd = s.lnBTC
cmdLnd = s.lnXSN

case pbp2p.CoinType_XSN:
cmdLnd = s.lnLTC

}

Expand Down Expand Up @@ -385,11 +405,12 @@ func (s *P2PServer) Swap(ctx context.Context, req *pbp2p.SwapReq) (*pbp2p.SwapRe
return ret, nil
}

func newP2PServer(xuPeer pbp2p.P2PClient, lnLTC lnrpc.LightningClient, lnBTC lnrpc.LightningClient) *P2PServer {
func newP2PServer(xuPeer pbp2p.P2PClient, lnLTC lnrpc.LightningClient, lnBTC lnrpc.LightningClient, lnXSN lnrpc.LightningClient) *P2PServer {
s := &P2PServer{
xuPeer: xuPeer,
lnLTC: lnLTC,
lnBTC: lnBTC,
lnXSN: lnXSN,
}
return s
}
Expand Down Expand Up @@ -450,6 +471,11 @@ func main() {
Value: "localhost:10002",
Usage: "RPC host:port of LND connected to LTC chain",
},
cli.StringFlag{
Name: "lnd-rpc-xsn",
Value: "localhost:10003",
Usage: "RPC host:port of LND connected to XSN chain",
},

}

Expand All @@ -462,6 +488,9 @@ func main() {
lnBTC, close := getLNDClient(c,"lnd-rpc-btc")
defer close()

lnXSN, close := getLNDClient(c,"lnd-rpc-xsn")
defer close()

xuPeer, close := getClient(c)
defer close()
log.Printf("Got peer connection")
Expand All @@ -475,7 +504,7 @@ func main() {

var opts []grpc.ServerOption
grpcServer := grpc.NewServer(opts...)
p2pServer := newP2PServer(xuPeer, lnLTC, lnBTC)
p2pServer := newP2PServer(xuPeer, lnLTC, lnBTC, lnXSN)
pb.RegisterHashResolverServer(grpcServer, newServer(p2pServer))
pbp2p.RegisterP2PServer(grpcServer, p2pServer)
log.Printf("Server ready")
Expand Down
3 changes: 3 additions & 0 deletions swapp2p/swap_p2p.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions swapp2p/swap_p2p.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package swapresolver;
enum CoinType {
BTC = 0;
LTC = 1;
XSN = 2;
}

service P2P {
Expand Down
3 changes: 2 additions & 1 deletion swapp2p/swap_p2p.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"type": "string",
"enum": [
"BTC",
"LTC"
"LTC",
"XSN"
],
"default": "BTC"
},
Expand Down

0 comments on commit 038f39f

Please sign in to comment.