Skip to content

Commit

Permalink
WIP: Implement gRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenroose committed Apr 2, 2018
1 parent e70a0fe commit 466cf23
Show file tree
Hide file tree
Showing 11 changed files with 7,548 additions and 191 deletions.
4,093 changes: 4,093 additions & 0 deletions btcrpc/btcrpc.pb.go

Large diffs are not rendered by default.

682 changes: 682 additions & 0 deletions btcrpc/btcrpc.proto

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions btcrpc/generate-protos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

# Generate the protos.
protoc -I/usr/local/include -I. \
-I$GOPATH/src \
--go_out=plugins=grpc:. \
btcrpc.proto

46 changes: 46 additions & 0 deletions btcrpc/rpcutils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package btcrpc

import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
)

// NewBlockLocatorHash creates a new BlockLocator using the given block hash.
func NewBlockLocatorHash(hash *chainhash.Hash) *BlockLocator {
return &BlockLocator{
Locator: &BlockLocator_Hash{
Hash: hash[:],
},
}
}

// NewBlockLocatorHeight creates a new BlockLocator using the given block height.
func NewBlockLocatorHeight(height int32) *BlockLocator {
return &BlockLocator{
Locator: &BlockLocator_Height{
Height: height,
},
}
}

// NewTransactionFilter creates a new transaction filter with the given addresses
// and outpoints.
func NewTransactionFilter(addresses []btcutil.Address, outpoints []wire.OutPoint) *TransactionFilter {
f := TransactionFilter{
Addresses: make([]string, len(addresses)),
Outpoints: make([]*Transaction_Input_Outpoint, len(outpoints)),
}

for i, addr := range addresses {
f.Addresses[i] = addr.EncodeAddress()
}
for i, op := range outpoints {
f.Outpoints[i] = &Transaction_Input_Outpoint{
Hash: op.Hash[:],
Index: op.Index,
}
}

return &f
}

0 comments on commit 466cf23

Please sign in to comment.