diff --git a/cmd/resolver-cli/main.go b/cmd/resolver-cli/main.go index 68c9355..f965580 100644 --- a/cmd/resolver-cli/main.go +++ b/cmd/resolver-cli/main.go @@ -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"){ @@ -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{ diff --git a/exchange-a/lnd/btc/start.bash b/exchange-a/lnd/btc/start.bash index 707f127..7b1fd03 100755 --- a/exchange-a/lnd/btc/start.bash +++ b/exchange-a/lnd/btc/start.bash @@ -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" diff --git a/exchange-a/lnd/ltc/start.bash b/exchange-a/lnd/ltc/start.bash index b60de3a..01449cb 100755 --- a/exchange-a/lnd/ltc/start.bash +++ b/exchange-a/lnd/ltc/start.bash @@ -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" + diff --git a/exchange-a/resolver/start.bash b/exchange-a/resolver/start.bash index 2045a18..0a5e69d 100755 --- a/exchange-a/resolver/start.bash +++ b/exchange-a/resolver/start.bash @@ -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 diff --git a/exchange-b/lnd/btc/start.bash b/exchange-b/lnd/btc/start.bash index 5551e28..de8e5a7 100755 --- a/exchange-b/lnd/btc/start.bash +++ b/exchange-b/lnd/btc/start.bash @@ -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" diff --git a/exchange-b/lnd/ltc/start.bash b/exchange-b/lnd/ltc/start.bash index e8598cf..f84a34e 100755 --- a/exchange-b/lnd/ltc/start.bash +++ b/exchange-b/lnd/ltc/start.bash @@ -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" diff --git a/exchange-b/resolver/start.bash b/exchange-b/resolver/start.bash index 6ca24e5..f6c54a8 100755 --- a/exchange-b/resolver/start.bash +++ b/exchange-b/resolver/start.bash @@ -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 diff --git a/resolver.go b/resolver.go index 68ee740..c92f7f2 100644 --- a/resolver.go +++ b/resolver.go @@ -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 @@ -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 } @@ -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) @@ -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) @@ -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 } @@ -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 } @@ -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", + }, } @@ -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") @@ -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") diff --git a/swapp2p/swap_p2p.pb.go b/swapp2p/swap_p2p.pb.go index b8b5146..7eab098 100644 --- a/swapp2p/swap_p2p.pb.go +++ b/swapp2p/swap_p2p.pb.go @@ -42,15 +42,18 @@ type CoinType int32 const ( CoinType_BTC CoinType = 0 CoinType_LTC CoinType = 1 + CoinType_XSN CoinType = 2 ) var CoinType_name = map[int32]string{ 0: "BTC", 1: "LTC", + 2: "XSN", } var CoinType_value = map[string]int32{ "BTC": 0, "LTC": 1, + "XSN": 2, } func (x CoinType) String() string { diff --git a/swapp2p/swap_p2p.proto b/swapp2p/swap_p2p.proto index 076afc4..7ab5845 100644 --- a/swapp2p/swap_p2p.proto +++ b/swapp2p/swap_p2p.proto @@ -12,6 +12,7 @@ package swapresolver; enum CoinType { BTC = 0; LTC = 1; + XSN = 2; } service P2P { diff --git a/swapp2p/swap_p2p.swagger.json b/swapp2p/swap_p2p.swagger.json index 67c8fe5..91a08be 100644 --- a/swapp2p/swap_p2p.swagger.json +++ b/swapp2p/swap_p2p.swagger.json @@ -20,7 +20,8 @@ "type": "string", "enum": [ "BTC", - "LTC" + "LTC", + "XSN" ], "default": "BTC" },