Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 52 additions & 4 deletions api/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
"github.com/OpenBazaar/multiwallet/litecoin"
"github.com/OpenBazaar/multiwallet/zcash"
"github.com/OpenBazaar/wallet-interface"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcutil"
"github.com/golang/protobuf/ptypes"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
Expand Down Expand Up @@ -134,14 +136,60 @@ func (s *server) HasKey(ctx context.Context, in *pb.Address) (*pb.BoolResponse,
}

func (s *server) Transactions(ctx context.Context, in *pb.CoinSelection) (*pb.TransactionList, error) {
// Stub
var list []*pb.Tx
ct := coinType(in.Coin)
wal, err := s.w.WalletForCurrencyCode(ct.CurrencyCode())
if err != nil {
return nil, err
}
txs, err := wal.Transactions()
if err != nil {
return nil, err
}
var list = make([]*pb.Tx, 0, len(txs))
for _, tx := range txs {
ts, err := ptypes.TimestampProto(tx.Timestamp)
if err != nil {
return nil, err
}
respTx := &pb.Tx{
Txid: tx.Txid,
Value: tx.Value,
Height: tx.Height,
WatchOnly: tx.WatchOnly,
Timestamp: ts,
Raw: tx.Bytes,
}
list = append(list, respTx)
}
return &pb.TransactionList{Transactions: list}, nil
}

func (s *server) GetTransaction(ctx context.Context, in *pb.Txid) (*pb.Tx, error) {
// Stub
respTx := &pb.Tx{}
ct := coinType(in.Coin)
wal, err := s.w.WalletForCurrencyCode(ct.CurrencyCode())
if err != nil {
return nil, err
}
ch, err := chainhash.NewHashFromStr(in.Hash)
if err != nil {
return nil, err
}
tx, err := wal.GetTransaction(*ch)
if err != nil {
return nil, err
}
ts, err := ptypes.TimestampProto(tx.Timestamp)
if err != nil {
return nil, err
}
respTx := &pb.Tx{
Txid: tx.Txid,
Value: tx.Value,
Height: tx.Height,
WatchOnly: tx.WatchOnly,
Timestamp: ts,
Raw: tx.Bytes,
}
return respTx, nil
}

Expand Down