Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

Commit

Permalink
Merge pull request Roasbeef#13 from ltcsuite/ltcutil/lastest
Browse files Browse the repository at this point in the history
Ltcutil/lastest
  • Loading branch information
losh11 authored Jun 11, 2020
2 parents 4faa85a + 97df170 commit 8a1fe75
Show file tree
Hide file tree
Showing 60 changed files with 1,158 additions and 519 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build and Test
on: [push, pull_request]
jobs:
build:
name: Go CI
runs-on: ubuntu-latest
strategy:
matrix:
go: [1.13, 1.14]
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- name: Check out source
uses: actions/checkout@v2
- name: Install Linters
run: "curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.26.0"
- name: Build
env:
GO111MODULE: "on"
run: go build ./...
- name: Test
env:
GO111MODULE: "on"
run: |
sh ./goclean.sh
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# ltcd

[![Build Status](https://travis-ci.org/ltcsuite/ltcd.png?branch=master)](https://travis-ci.org/ltcsuite/ltcd)
[![Build Status](https://github.com/btcsuite/btcd/workflows/Build%20and%20Test/badge.svg)](https://github.com/ltcsuite/ltcd/actions)
[![ISC License](https://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/ltcsuite/ltcd)

ltcd is an alternative full node bitcoin implementation written in Go (golang).

Expand Down
2 changes: 1 addition & 1 deletion blockchain/difficulty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestCalcWork(t *testing.T) {
}

for x, test := range tests {
bits := uint32(test.in)
bits := test.in

r := CalcWork(bits)
if r.Int64() != test.out {
Expand Down
21 changes: 16 additions & 5 deletions blockchain/indexers/addrindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ func serializeAddrIndexEntry(blockID uint32, txLoc wire.TxLoc) []byte {
// provided region struct according to the format described in detail above and
// uses the passed block hash fetching function in order to conver the block ID
// to the associated block hash.
func deserializeAddrIndexEntry(serialized []byte, region *database.BlockRegion, fetchBlockHash fetchBlockHashFunc) error {
func deserializeAddrIndexEntry(serialized []byte, region *database.BlockRegion,
fetchBlockHash fetchBlockHashFunc) error {

// Ensure there are enough bytes to decode.
if len(serialized) < txEntrySize {
return errDeserialize("unexpected end of data")
Expand All @@ -182,7 +184,9 @@ func keyForLevel(addrKey [addrKeySize]byte, level uint8) [levelKeySize]byte {

// dbPutAddrIndexEntry updates the address index to include the provided entry
// according to the level-based scheme described in detail above.
func dbPutAddrIndexEntry(bucket internalBucket, addrKey [addrKeySize]byte, blockID uint32, txLoc wire.TxLoc) error {
func dbPutAddrIndexEntry(bucket internalBucket, addrKey [addrKeySize]byte,
blockID uint32, txLoc wire.TxLoc) error {

// Start with level 0 and its initial max number of entries.
curLevel := uint8(0)
maxLevelBytes := level0MaxEntries * txEntrySize
Expand Down Expand Up @@ -253,7 +257,10 @@ func dbPutAddrIndexEntry(bucket internalBucket, addrKey [addrKeySize]byte, block
// the given address key and the number of entries skipped since it could have
// been less in the case where there are less total entries than the requested
// number of entries to skip.
func dbFetchAddrIndexEntries(bucket internalBucket, addrKey [addrKeySize]byte, numToSkip, numRequested uint32, reverse bool, fetchBlockHash fetchBlockHashFunc) ([]database.BlockRegion, uint32, error) {
func dbFetchAddrIndexEntries(bucket internalBucket, addrKey [addrKeySize]byte,
numToSkip, numRequested uint32, reverse bool,
fetchBlockHash fetchBlockHashFunc) ([]database.BlockRegion, uint32, error) {

// When the reverse flag is not set, all levels need to be fetched
// because numToSkip and numRequested are counted from the oldest
// transactions (highest level) and thus the total count is needed.
Expand Down Expand Up @@ -356,7 +363,9 @@ func maxEntriesForLevel(level uint8) int {
// dbRemoveAddrIndexEntries removes the specified number of entries from from
// the address index for the provided key. An assertion error will be returned
// if the count exceeds the total number of entries in the index.
func dbRemoveAddrIndexEntries(bucket internalBucket, addrKey [addrKeySize]byte, count int) error {
func dbRemoveAddrIndexEntries(bucket internalBucket, addrKey [addrKeySize]byte,
count int) error {

// Nothing to do if no entries are being deleted.
if count <= 0 {
return nil
Expand Down Expand Up @@ -796,7 +805,9 @@ func (idx *AddrIndex) DisconnectBlock(dbTx database.Tx, block *ltcutil.Block,
// that involve a given address.
//
// This function is safe for concurrent access.
func (idx *AddrIndex) TxRegionsForAddress(dbTx database.Tx, addr ltcutil.Address, numToSkip, numRequested uint32, reverse bool) ([]database.BlockRegion, uint32, error) {
func (idx *AddrIndex) TxRegionsForAddress(dbTx database.Tx, addr ltcutil.Address,
numToSkip, numRequested uint32, reverse bool) ([]database.BlockRegion, uint32, error) {

addrKey, err := addrToKey(addr)
if err != nil {
return nil, 0, err
Expand Down
4 changes: 2 additions & 2 deletions blockchain/indexers/addrindex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (b *addrIndexBucket) printLevels(addrKey [addrKeySize]byte) string {
if !bytes.Equal(k[:levelOffset], addrKey[:]) {
continue
}
level := uint8(k[levelOffset])
level := k[levelOffset]
if level > highestLevel {
highestLevel = level
}
Expand Down Expand Up @@ -105,7 +105,7 @@ func (b *addrIndexBucket) sanityCheck(addrKey [addrKeySize]byte, expectedTotal i
if !bytes.Equal(k[:levelOffset], addrKey[:]) {
continue
}
level := uint8(k[levelOffset])
level := k[levelOffset]
if level > highestLevel {
highestLevel = level
}
Expand Down
6 changes: 3 additions & 3 deletions btcec/pubkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ func TestPubKeys(t *testing.T) {
var pkStr []byte
switch test.format {
case pubkeyUncompressed:
pkStr = (*PublicKey)(pk).SerializeUncompressed()
pkStr = pk.SerializeUncompressed()
case pubkeyCompressed:
pkStr = (*PublicKey)(pk).SerializeCompressed()
pkStr = pk.SerializeCompressed()
case pubkeyHybrid:
pkStr = (*PublicKey)(pk).SerializeHybrid()
pkStr = pk.SerializeHybrid()
}
if !bytes.Equal(test.key, pkStr) {
t.Errorf("%s pubkey: serialized keys do not match.",
Expand Down
3 changes: 1 addition & 2 deletions btcec/signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,7 @@ func TestSignatureSerialize(t *testing.T) {

func testSignCompact(t *testing.T, tag string, curve *KoblitzCurve,
data []byte, isCompressed bool) {
tmp, _ := NewPrivateKey(curve)
priv := (*PrivateKey)(tmp)
priv, _ := NewPrivateKey(curve)

hashed := []byte("testing")
sig, err := SignCompact(curve, priv, hashed, isCompressed)
Expand Down
18 changes: 18 additions & 0 deletions btcjson/btcdextcmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ func NewDebugLevelCmd(levelSpec string) *DebugLevelCmd {
}
}

// GenerateToAddressCmd defines the generatetoaddress JSON-RPC command.
type GenerateToAddressCmd struct {
NumBlocks int64
Address string
MaxTries *int64 `jsonrpcdefault:"1000000"`
}

// NewGenerateToAddressCmd returns a new instance which can be used to issue a
// generatetoaddress JSON-RPC command.
func NewGenerateToAddressCmd(numBlocks int64, address string, maxTries *int64) *GenerateToAddressCmd {
return &GenerateToAddressCmd{
NumBlocks: numBlocks,
Address: address,
MaxTries: maxTries,
}
}

// GenerateCmd defines the generate JSON-RPC command.
type GenerateCmd struct {
NumBlocks uint32
Expand Down Expand Up @@ -131,6 +148,7 @@ func init() {
MustRegisterCmd("debuglevel", (*DebugLevelCmd)(nil), flags)
MustRegisterCmd("node", (*NodeCmd)(nil), flags)
MustRegisterCmd("generate", (*GenerateCmd)(nil), flags)
MustRegisterCmd("generatetoaddress", (*GenerateToAddressCmd)(nil), flags)
MustRegisterCmd("getbestblock", (*GetBestBlockCmd)(nil), flags)
MustRegisterCmd("getcurrentnet", (*GetCurrentNetCmd)(nil), flags)
MustRegisterCmd("getheaders", (*GetHeadersCmd)(nil), flags)
Expand Down
18 changes: 18 additions & 0 deletions btcjson/btcdextcmds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ func TestBtcdExtCmds(t *testing.T) {
NumBlocks: 1,
},
},
{
name: "generatetoaddress",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("generatetoaddress", 1, "1Address")
},
staticCmd: func() interface{} {
return btcjson.NewGenerateToAddressCmd(1, "1Address", nil)
},
marshalled: `{"jsonrpc":"1.0","method":"generatetoaddress","params":[1,"1Address"],"id":1}`,
unmarshalled: &btcjson.GenerateToAddressCmd{
NumBlocks: 1,
Address: "1Address",
MaxTries: func() *int64 {
var i int64 = 1000000
return &i
}(),
},
},
{
name: "getbestblock",
newCmd: func() (interface{}, error) {
Expand Down
53 changes: 48 additions & 5 deletions btcjson/chainsvrcmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,18 @@ func NewGetBestBlockHashCmd() *GetBestBlockHashCmd {
// GetBlockCmd defines the getblock JSON-RPC command.
type GetBlockCmd struct {
Hash string
Verbose *bool `jsonrpcdefault:"true"`
VerboseTx *bool `jsonrpcdefault:"false"`
Verbosity *int `jsonrpcdefault:"1"`
}

// NewGetBlockCmd returns a new instance which can be used to issue a getblock
// JSON-RPC command.
//
// The parameters which are pointers indicate they are optional. Passing nil
// for optional parameters will use the default value.
func NewGetBlockCmd(hash string, verbose, verboseTx *bool) *GetBlockCmd {
func NewGetBlockCmd(hash string, verbosity *int) *GetBlockCmd {
return &GetBlockCmd{
Hash: hash,
Verbose: verbose,
VerboseTx: verboseTx,
Verbosity: verbosity,
}
}

Expand Down Expand Up @@ -193,6 +191,50 @@ func NewGetBlockHeaderCmd(hash string, verbose *bool) *GetBlockHeaderCmd {
}
}

// HashOrHeight defines a type that can be used as hash_or_height value in JSON-RPC commands.
type HashOrHeight struct {
Value interface{}
}

// MarshalJSON implements the json.Marshaler interface
func (h HashOrHeight) MarshalJSON() ([]byte, error) {
return json.Marshal(h.Value)
}

// UnmarshalJSON implements the json.Unmarshaler interface
func (h *HashOrHeight) UnmarshalJSON(data []byte) error {
var unmarshalled interface{}
if err := json.Unmarshal(data, &unmarshalled); err != nil {
return err
}

switch v := unmarshalled.(type) {
case float64:
h.Value = int(v)
case string:
h.Value = v
default:
return fmt.Errorf("invalid hash_or_height value: %v", unmarshalled)
}

return nil
}

// GetBlockStatsCmd defines the getblockstats JSON-RPC command.
type GetBlockStatsCmd struct {
HashOrHeight HashOrHeight
Stats *[]string
}

// NewGetBlockStatsCmd returns a new instance which can be used to issue a
// getblockstats JSON-RPC command. Either height or hash must be specified.
func NewGetBlockStatsCmd(hashOrHeight HashOrHeight, stats *[]string) *GetBlockStatsCmd {
return &GetBlockStatsCmd{
HashOrHeight: hashOrHeight,
Stats: stats,
}
}

// TemplateRequest is a request object as defined in BIP22
// (https://en.bitcoin.it/wiki/BIP_0022), it is optionally provided as an
// pointer argument to GetBlockTemplateCmd.
Expand Down Expand Up @@ -800,6 +842,7 @@ func init() {
MustRegisterCmd("getblockcount", (*GetBlockCountCmd)(nil), flags)
MustRegisterCmd("getblockhash", (*GetBlockHashCmd)(nil), flags)
MustRegisterCmd("getblockheader", (*GetBlockHeaderCmd)(nil), flags)
MustRegisterCmd("getblockstats", (*GetBlockStatsCmd)(nil), flags)
MustRegisterCmd("getblocktemplate", (*GetBlockTemplateCmd)(nil), flags)
MustRegisterCmd("getcfilter", (*GetCFilterCmd)(nil), flags)
MustRegisterCmd("getcfilterheader", (*GetCFilterHeaderCmd)(nil), flags)
Expand Down
Loading

0 comments on commit 8a1fe75

Please sign in to comment.