Skip to content

Commit

Permalink
WIP: Implement gRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenroose committed May 22, 2018
1 parent ccc85fd commit 7631359
Show file tree
Hide file tree
Showing 12 changed files with 10,036 additions and 191 deletions.
5,859 changes: 5,859 additions & 0 deletions btcrpc/btcrpc.pb.go

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

684 changes: 684 additions & 0 deletions btcrpc/client/client.go

Large diffs are not rendered by default.

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

VERSION_PROTOC="libprotoc 3.5.1"

# Make sure the correct version of protoc is installed.
LOCAL_PROTOC="$(protoc --version)"
if [ "$LOCAL_PROTOC" != "$VERSION_PROTOC" ]
then
echo "Wrong protoc version. Got $LOCAL_PROTOC; need $VERSION_PROTOC."
exit 1
fi

#TODO add version check for
# - protoc-gen-go
# - protoc-gen-grpc-gateway

# 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 7631359

Please sign in to comment.