Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: trezor/blockbook
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: guardaco/blockbook
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: guarda-changes
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.

Commits on Aug 22, 2020

  1. Merge pull request #16 from trezor/master

    MErge
    alexeirbv authored Aug 22, 2020
    Copy the full SHA
    f8b2482 View commit details

Commits on Sep 10, 2020

  1. Merge pull request #22 from trezor/master

    from trezor master
    matyushkins authored Sep 10, 2020
    Copy the full SHA
    f6c3537 View commit details

Commits on Sep 28, 2020

  1. Merge pull request #24 from trezor/master

    from master trezor
    matyushkins authored Sep 28, 2020
    Copy the full SHA
    07a2b0e View commit details

Commits on Oct 8, 2020

  1. Merge pull request #26 from trezor/master

    etc: 1.11.12 -> 1.11.15
    matyushkins authored Oct 8, 2020
    Copy the full SHA
    569cb13 View commit details

Commits on Nov 12, 2020

  1. Merge pull request #28 from trezor/master

    from trezor master
    matyushkins authored Nov 12, 2020
    Copy the full SHA
    6d6df81 View commit details

Commits on Nov 23, 2020

  1. Merge pull request #32 from trezor/master

    from master
    matyushkins authored Nov 23, 2020
    Copy the full SHA
    7a152d1 View commit details

Commits on Nov 26, 2020

  1. Zcoin -> Firo

    araarakelyan1985 committed Nov 26, 2020
    Copy the full SHA
    bc3dd19 View commit details

Commits on Dec 8, 2020

  1. Copy the full SHA
    ab30a9c View commit details
  2. Add optional spendingIndex

    martinboehm authored and araarakelyan1985 committed Dec 8, 2020
    Copy the full SHA
    91f558c View commit details
  3. Fix tests because of spendTxIndexing

    thebevrishot authored and araarakelyan1985 committed Dec 8, 2020
    Copy the full SHA
    753577d View commit details

Commits on Dec 15, 2020

  1. Fix showing Sigma/Lelantus related addresses in transaction inputs an…

    …d display Hidden for value of lelantus transactions
    araarakelyan1985 committed Dec 15, 2020
    Copy the full SHA
    ee4b4c3 View commit details

Commits on Dec 23, 2020

  1. Merge pull request #36 from trezor/master

    from trezor master
    matyushkins authored Dec 23, 2020
    Copy the full SHA
    0dee5d9 View commit details
  2. Merge pull request #37 from firoorg/firo-spendIndex

    Firo spend index
    matyushkins authored Dec 23, 2020
    Copy the full SHA
    5f4759c View commit details
  3. ScriptPubKey was added

    matyushkins committed Dec 23, 2020
    Copy the full SHA
    3846115 View commit details
  4. Copy the full SHA
    7b2196d View commit details

Commits on Dec 25, 2020

  1. add rdd coin

    matyushkins committed Dec 25, 2020
    Copy the full SHA
    4188e73 View commit details

Commits on Dec 29, 2020

  1. Merge pull request #39 from trezor/master

    from master
    matyushkins authored Dec 29, 2020
    Copy the full SHA
    b5b99a5 View commit details

Commits on Jan 11, 2021

  1. Merge pull request #41 from trezor/master

    bch (+testnet): 22.1.0 → 22.2.0
    matyushkins authored Jan 11, 2021
    Copy the full SHA
    1d7e83f View commit details
  2. Copy the full SHA
    b470346 View commit details
  3. Merge pull request #40 from guardaco/master

    from Master
    alexeirbv authored Jan 11, 2021
    Copy the full SHA
    b15470a View commit details

Commits on Jan 18, 2021

  1. Merge pull request #42 from trezor/master

    from Trezor master
    matyushkins authored Jan 18, 2021
    Copy the full SHA
    0c05230 View commit details
  2. Merge pull request #43 from guardaco/master

    Master
    matyushkins authored Jan 18, 2021
    Copy the full SHA
    8d50d34 View commit details

Commits on Jan 22, 2021

  1. Merge pull request #44 from trezor/master

    from trezor master
    matyushkins authored Jan 22, 2021
    Copy the full SHA
    0b04238 View commit details
  2. Copy the full SHA
    3b4bf4b View commit details
  3. Merge pull request #45 from guardaco/master

    Master
    matyushkins authored Jan 22, 2021
    Copy the full SHA
    a436ea2 View commit details
  4. fix func after merge

    matyushkins committed Jan 22, 2021
    Copy the full SHA
    f657117 View commit details

Commits on Feb 18, 2021

  1. Merge pull request #46 from trezor/master

    from trezor master
    matyushkins authored Feb 18, 2021
    Copy the full SHA
    33ce50d View commit details
  2. Merge pull request #47 from guardaco/master

    from Master
    matyushkins authored Feb 18, 2021
    Copy the full SHA
    794e1f5 View commit details

Commits on Mar 5, 2021

  1. Merge pull request #48 from trezor/master

    from trezor master
    matyushkins authored Mar 5, 2021
    Copy the full SHA
    8da7ae0 View commit details
  2. Merge pull request #49 from guardaco/master

    Master
    matyushkins authored Mar 5, 2021
    Copy the full SHA
    3337b9c View commit details

Commits on Mar 9, 2021

  1. Merge pull request #50 from trezor/master

    from trezor
    matyushkins authored Mar 9, 2021
    Copy the full SHA
    0cf753a View commit details
  2. Merge pull request #51 from guardaco/master

    Master
    matyushkins authored Mar 9, 2021
    Copy the full SHA
    f4f584c View commit details

Commits on Mar 25, 2021

  1. Merge pull request #52 from trezor/master

    merge
    alexeirbv authored Mar 25, 2021
    Copy the full SHA
    2e28d94 View commit details

Commits on Mar 26, 2021

  1. Merge pull request #53 from guardaco/master

    Master
    matyushkins authored Mar 26, 2021
    Copy the full SHA
    42b9e49 View commit details

Commits on Apr 22, 2021

  1. Merge pull request #54 from trezor/master

    from trezor
    matyushkins authored Apr 22, 2021
    Copy the full SHA
    53b9341 View commit details
  2. Merge pull request #55 from guardaco/master

    Master
    matyushkins authored Apr 22, 2021
    Copy the full SHA
    f3aa72b View commit details

Commits on Apr 23, 2021

  1. Copy the full SHA
    c297ee9 View commit details
  2. Merge pull request #56 from guardaco/feature/GRD-2701-BTCV-bitcoin-vault

    GRD-2701: Add BTCV (Bitcoin Vault) adapter
    waterelder authored Apr 23, 2021
    Copy the full SHA
    985a5ba View commit details

Commits on May 4, 2021

  1. Merge pull request #58 from trezor/master

    Fixing the name of the Bitcoin Gold Testnet
    matyushkins authored May 4, 2021
    Copy the full SHA
    28714e4 View commit details
  2. Merge pull request #61 from guardaco/master

    Master
    matyushkins authored May 4, 2021
    Copy the full SHA
    8cb464a View commit details

Commits on May 7, 2021

  1. Merge pull request #62 from trezor/master

    Master
    matyushkins authored May 7, 2021
    Copy the full SHA
    18c567d View commit details
  2. Merge pull request #63 from guardaco/master

    Master
    matyushkins authored May 7, 2021
    Copy the full SHA
    037ddd4 View commit details

Commits on May 24, 2021

  1. Merge pull request #66 from trezor/master

    Master
    matyushkins authored May 24, 2021
    Copy the full SHA
    8bdaec2 View commit details
  2. Merge pull request #67 from guardaco/master

    Master
    matyushkins authored May 24, 2021
    Copy the full SHA
    ad34131 View commit details

Commits on Jun 4, 2021

  1. Merge pull request #68 from trezor/master

    Master
    matyushkins authored Jun 4, 2021
    Copy the full SHA
    52efd2c View commit details
  2. Merge pull request #69 from guardaco/master

    Master
    matyushkins authored Jun 4, 2021
    Copy the full SHA
    4cee4b8 View commit details

Commits on Jun 7, 2021

  1. add host url

    matyushkins committed Jun 7, 2021
    Copy the full SHA
    be185e2 View commit details
  2. fix log for host

    matyushkins committed Jun 7, 2021
    Copy the full SHA
    19c53a0 View commit details
  3. Copy the full SHA
    d4561d5 View commit details
  4. add path to url

    matyushkins committed Jun 7, 2021
    Copy the full SHA
    1993f88 View commit details
Showing with 3,566 additions and 77 deletions.
  1. +7 −0 README.md
  2. +1 −0 api/types.go
  3. +2 −0 api/typesv1.go
  4. +58 −1 api/worker.go
  5. +64 −0 bchain/coins/aryacoin/aryacoinparser.go
  6. +58 −0 bchain/coins/aryacoin/aryacoinrpc.go
  7. +104 −0 bchain/coins/bitcoinvault/bitcoinvaultparser.go
  8. +344 −0 bchain/coins/bitcoinvault/bitcoinvaultparser_test.go
  9. +73 −0 bchain/coins/bitcoinvault/bitcoinvaultrpc.go
  10. +1 −0 bchain/coins/bitcoinvault/testdata/block_dump.23359
  11. +1 −0 bchain/coins/bitcoinvault/testdata/block_dump.3125
  12. +1 −0 bchain/coins/bitcoinvault/testdata/block_dump.58420
  13. +1 −0 bchain/coins/bitcoinvault/testdata/block_dump.9718
  14. +25 −0 bchain/coins/blockchain.go
  15. +64 −0 bchain/coins/creamcoin/creamcoinparser.go
  16. +59 −0 bchain/coins/creamcoin/creamcoinrpc.go
  17. +1 −0 bchain/coins/dcr/decredrpc.go
  18. +1 −0 bchain/coins/ecash/ecashrpc.go
  19. +25 −0 bchain/coins/eth/ethrpc.go
  20. +14 −0 bchain/coins/firo/firoparser.go
  21. +97 −0 bchain/coins/kmd/kmdparser.go
  22. +115 −0 bchain/coins/kmd/kmdrpc.go
  23. +196 −0 bchain/coins/rdd/rddcoinparser.go
  24. +102 −0 bchain/coins/rdd/rddrpc.go
  25. +64 −0 bchain/coins/verge/vergeparser.go
  26. +245 −0 bchain/coins/verge/vergeparser_test.go
  27. +103 −0 bchain/coins/verge/vergerpc.go
  28. +98 −0 bchain/coins/yec/ycashparser.go
  29. +248 −0 bchain/coins/yec/ycashparser_test.go
  30. +115 −0 bchain/coins/yec/ycashrpc.go
  31. +10 −0 bchain/types.go
  32. +1 −1 build/docker/bin/Dockerfile
  33. +62 −0 configs/coins/aryacoin.json
  34. +69 −0 configs/coins/bcashabc.json
  35. +61 −0 configs/coins/bcashsv_testnet.json
  36. +73 −0 configs/coins/bitcoinvault.json
  37. +62 −0 configs/coins/callisto.json
  38. +62 −0 configs/coins/creamcoin.json
  39. +61 −0 configs/coins/ethereum_pow.json
  40. +60 −0 configs/coins/expanse.json
  41. +66 −0 configs/coins/kmd.json
  42. +64 −0 configs/coins/polygon.json
  43. +67 −0 configs/coins/reddcoin.json
  44. +64 −0 configs/coins/ubiq.json
  45. +64 −0 configs/coins/ubiq_testnet.json
  46. +69 −0 configs/coins/verge.json
  47. +67 −0 configs/coins/ycash.json
  48. +65 −0 configs/coins/zcoin_testnet.json
  49. +4 −0 db/rocksdb.go
  50. +70 −75 docs/ports.md
  51. +1 −0 go.mod
  52. +22 −0 go.sum
  53. +1 −0 server/internal.go
  54. +25 −0 server/public.go
  55. +2 −0 server/public_test.go
  56. +2 −0 static/robots.txt
  57. +3 −0 tests/rpc/testdata/bitcoinvault.json
  58. +54 −0 tests/rpc/testdata/verge.json
  59. +3 −0 tests/sync/testdata/bitcoinvault.json
  60. +38 −0 tests/sync/testdata/verge.json
  61. +7 −0 tests/tests.json
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@

# Blockbook

**FOR INTERNAL GUARDA WALLET PURPOSES ONLY. PLEASE USE UPSTREAM INSTEAD!**

**Blockbook** is back-end service for Trezor wallet. Main features of **Blockbook** are:

- index of addresses and address balances of the connected block chain
@@ -11,6 +13,11 @@
- support of multiple coins (Bitcoin and Ethereum type) with easy extensibility to other coins
- scripts for easy creation of debian packages for backend and blockbook

## For Guarda Dev Team

- Branch `guarda-changes` only for production use. DO NOT MERGE UNTESTED CHANGES!
- Branch `master` for compability with Trezor upstream. ONLY PRs FROM UPSTREAM ALLOWED!

## Build and installation instructions

Officially supported platform is **Debian Linux** and **AMD64** architecture.
1 change: 1 addition & 0 deletions api/types.go
Original file line number Diff line number Diff line change
@@ -357,6 +357,7 @@ type Utxo struct {
Path string `json:"path,omitempty"`
Locktime uint32 `json:"lockTime,omitempty"`
Coinbase bool `json:"coinbase,omitempty"`
ScriptPubKey string `json:"scriptPubKey,omitempty"`
}

// Utxos is array of Utxo
2 changes: 2 additions & 0 deletions api/typesv1.go
Original file line number Diff line number Diff line change
@@ -92,6 +92,7 @@ type AddressUtxoV1 struct {
AmountSat big.Int `json:"satoshis"`
Height int `json:"height,omitempty"`
Confirmations int `json:"confirmations"`
ScriptPubKey string `json:"scriptPubKey"`
}

// BlockV1 contains information about block
@@ -205,6 +206,7 @@ func (w *Worker) AddressUtxoToV1(au Utxos) []AddressUtxoV1 {
Height: utxo.Height,
Txid: utxo.Txid,
Vout: uint32(utxo.Vout),
ScriptPubKey: utxo.ScriptPubKey,
}
}
return v1
59 changes: 58 additions & 1 deletion api/worker.go
Original file line number Diff line number Diff line change
@@ -287,6 +287,7 @@ func (w *Worker) getTransactionFromBchainTx(bchainTx *bchain.Tx, height int, spe
var pValInSat *big.Int
vins := make([]Vin, len(bchainTx.Vin))
rbf := false
var rawTxForInputValues *bchain.TxForInValues
for i := range bchainTx.Vin {
bchainVin := &bchainTx.Vin[i]
vin := &vins[i]
@@ -353,6 +354,28 @@ func (w *Worker) getTransactionFromBchainTx(bchainTx *bchain.Tx, height int, spe
if vin.ValueSat != nil {
valInSat.Add(&valInSat, (*big.Int)(vin.ValueSat))
}
} else {
vin.AddrDesc = w.chainParser.GetAddrDescForUnknownInput(bchainTx, i)
vin.Addresses, vin.IsAddress, err = w.chainParser.GetAddressesFromAddrDesc(vin.AddrDesc)
if rawTxForInputValues == nil {
rawTxJSON, err := w.chain.GetTransactionSpecific(bchainTx)
if err != nil {
glog.Error("Can't retrieve raw transaction with id ", bchainTx.Txid, ":", err)
}
if rawTxJSON != nil {
rawTxForInputValues = &bchain.TxForInValues{Vin: make([]bchain.VinValues, 0)}
err = json.Unmarshal(rawTxJSON, rawTxForInputValues)
}
}
if rawTxForInputValues != nil && rawTxForInputValues.Vin != nil && len(rawTxForInputValues.Vin) > i {
inputValue, err := w.chainParser.AmountToBigInt(rawTxForInputValues.Vin[i].Value)
if err == nil && inputValue.Cmp(big.NewInt(0)) != 0 {
vin.ValueSat = (*Amount)(&inputValue)
if vin.ValueSat != nil {
valInSat.Add(&valInSat, (*big.Int)(vin.ValueSat))
}
}
}
}
} else if w.chainType == bchain.ChainEthereumType {
if len(bchainVin.Addresses) > 0 {
@@ -834,6 +857,7 @@ func (w *Worker) txFromTxAddress(txid string, ta *db.TxAddresses, bi *db.BlockIn
var err error
var valInSat, valOutSat, feesSat big.Int
vins := make([]Vin, len(ta.Inputs))
var rawTxForInputValues *bchain.TxForInValues
for i := range ta.Inputs {
tai := &ta.Inputs[i]
vin := &vins[i]
@@ -842,7 +866,30 @@ func (w *Worker) txFromTxAddress(txid string, ta *db.TxAddresses, bi *db.BlockIn
valInSat.Add(&valInSat, &tai.ValueSat)
vin.Addresses, vin.IsAddress, err = tai.Addresses(w.chainParser)
if err != nil {
glog.Errorf("tai.Addresses error %v, tx %v, input %v, tai %+v", err, txid, i, tai)
//glog.Errorf("tai.Addresses error %v, tx %v, input %v, tai %+v", err, txid, i, tai)
} else {
if vin.Txid == "" {
if rawTxForInputValues == nil {
bchainTx, err := w.chain.GetTransaction(txid)
rawTxJSON, err := w.chain.GetTransactionSpecific(bchainTx)
if err != nil {
glog.Error("Can't retrieve raw transaction with id ", txid, ":", err)
}
if rawTxJSON != nil {
rawTxForInputValues = &bchain.TxForInValues{Vin: make([]bchain.VinValues, 0)}
err = json.Unmarshal(rawTxJSON, rawTxForInputValues)
}
}
if rawTxForInputValues != nil && rawTxForInputValues.Vin != nil && len(rawTxForInputValues.Vin) > i {
inputValue, err := w.chainParser.AmountToBigInt(rawTxForInputValues.Vin[i].Value)
if err == nil && inputValue.Cmp(big.NewInt(0)) != 0 {
vin.ValueSat = (*Amount)(&inputValue)
if vin.ValueSat != nil {
valInSat.Add(&valInSat, (*big.Int)(vin.ValueSat))
}
}
}
}
}
if w.db.HasExtendedIndex() {
vin.Txid = tai.Txid
@@ -1684,6 +1731,7 @@ func (w *Worker) getAddrDescUtxo(addrDesc bchain.AddressDescriptor, ba *db.AddrB
AmountSat: (*Amount)(&vout.ValueSat),
Locktime: bchainTx.LockTime,
Coinbase: coinbase,
ScriptPubKey: vout.ScriptPubKey.Hex,
})
inMempool[bchainTx.Txid] = struct{}{}
}
@@ -1731,6 +1779,14 @@ func (w *Worker) getAddrDescUtxo(addrDesc bchain.AddressDescriptor, ba *db.AddrB
coinbase = true
}
}
bchainTx, height, err := w.txCache.GetTransaction(txid)
if err != nil {
if err == bchain.ErrTxNotFound {
return nil, NewAPIError(fmt.Sprintf("Transaction '%v' not found", txid), true)
}
return nil, NewAPIError(fmt.Sprintf("Transaction '%v' not found (%v)", txid, err), true)
}
transaction, err := w.GetTransactionFromBchainTx(bchainTx, height, false, false)
_, e = inMempool[txid]
if !e {
utxos = append(utxos, Utxo{
@@ -1740,6 +1796,7 @@ func (w *Worker) getAddrDescUtxo(addrDesc bchain.AddressDescriptor, ba *db.AddrB
Height: int(utxo.Height),
Confirmations: confirmations,
Coinbase: coinbase,
ScriptPubKey: transaction.Vout[utxo.Vout].Hex,
})
}
}
64 changes: 64 additions & 0 deletions bchain/coins/aryacoin/aryacoinparser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package aryacoin

import (
"github.com/trezor/blockbook/bchain/coins/btc"

"github.com/martinboehm/btcd/wire"
"github.com/martinboehm/btcutil/chaincfg"
)

// magic numbers
const (
MainnetMagic wire.BitcoinNet = 0xe7eae188
TestnetMagic wire.BitcoinNet = 0xf1c8d2fd
)

// chain parameters
var (
MainNetParams chaincfg.Params
TestNetParams chaincfg.Params
)

func init() {
MainNetParams = chaincfg.MainNetParams
MainNetParams.Net = MainnetMagic
MainNetParams.PubKeyHashAddrID = []byte{23}
MainNetParams.ScriptHashAddrID = []byte{5}
MainNetParams.Bech32HRPSegwit = "arya"

TestNetParams = chaincfg.TestNet3Params
TestNetParams.Net = TestnetMagic
TestNetParams.PubKeyHashAddrID = []byte{111}
TestNetParams.ScriptHashAddrID = []byte{196}
TestNetParams.Bech32HRPSegwit = "arya"
}

// AryaCoinParser handle
type AryaCoinParser struct {
*btc.BitcoinLikeParser
}

// NewAryaCoinParser returns new AryaCoinParser instance
func NewAryaCoinParser(params *chaincfg.Params, c *btc.Configuration) *AryaCoinParser {
return &AryaCoinParser{BitcoinLikeParser: btc.NewBitcoinLikeParser(params, c)}
}

// GetChainParams contains network parameters for the main AryaCoin network,
// and the test AryaCoin network
func GetChainParams(chain string) *chaincfg.Params {
if !chaincfg.IsRegistered(&MainNetParams) {
err := chaincfg.Register(&MainNetParams)
if err == nil {
err = chaincfg.Register(&TestNetParams)
}
if err != nil {
panic(err)
}
}
switch chain {
case "test":
return &TestNetParams
default:
return &MainNetParams
}
}
58 changes: 58 additions & 0 deletions bchain/coins/aryacoin/aryacoinrpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package aryacoin

import (
"github.com/trezor/blockbook/bchain"
"github.com/trezor/blockbook/bchain/coins/btc"
"encoding/json"

"github.com/golang/glog"
)

// AryaCoinRPC is an interface to JSON-RPC bitcoind service.
type AryaCoinRPC struct {
*btc.BitcoinRPC
}

// NewAryaCoinRPC returns new AryaCoinRPC instance.
func NewAryaCoinRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error) {
b, err := btc.NewBitcoinRPC(config, pushHandler)
if err != nil {
return nil, err
}

s := &AryaCoinRPC{
BitcoinRPC: b.(*btc.BitcoinRPC),
}
s.RPCMarshaler = btc.JSONMarshalerV1{}
s.ChainConfig.SupportsEstimateFee = false

return s, nil
}

// Initialize initializes AryaCoinRPC instance.
func (b *AryaCoinRPC) Initialize() error {
ci, err := b.GetChainInfo()
if err != nil {
return err
}
chainName := ci.Chain

glog.Info("Chain name ", chainName)
params := GetChainParams(chainName)

// always create parser
b.Parser = NewAryaCoinParser(params, b.ChainConfig)

// parameters for getInfo request
if params.Net == MainnetMagic {
b.Testnet = false
b.Network = "livenet"
} else {
b.Testnet = true
b.Network = "testnet"
}

glog.Info("rpc: block chain ", params.Name)

return nil
}
104 changes: 104 additions & 0 deletions bchain/coins/bitcoinvault/bitcoinvaultparser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package bitcoinvault

import (
"bytes"

"github.com/martinboehm/btcd/wire"
"github.com/martinboehm/btcutil/chaincfg"
"github.com/trezor/blockbook/bchain"
"github.com/trezor/blockbook/bchain/coins/btc"
"github.com/trezor/blockbook/bchain/coins/utils"
)

// magic numbers
const (
MainnetMagic wire.BitcoinNet = 0xc0c0c0c0
)

// chain parameters
var (
MainNetParams chaincfg.Params
)

// From https://github.com/bitcoinvault/bitcoinvault/blob/a6ab4e7a6dda8e2b8fda4a6c4a558bd412f23d89/src/policy/auxpow.h#L11
// Except these are not block hashes, but their parent block hashes
var FAKE_AUXPOW_PREFORK_BLOCK_PARENTS = map[string]bool{
"0000000000000000144c7fb7dad69be270035fa2d7f4652819369d9e3bb8023d": true,
"000000000000000017b3b639f6f4ff8618c0fe5fbc44c39fa924a60974be6a2d": true,
"0000000000000000022a3e19cd72f7012a2089fa5854ac42374bd48c010f1f4f": true,
"00000000000000001e8818e5c81c2f224fbf21f7be90888f4c6314bb56f11d3f": true,
};

func isFakeAuxpowPreforkBlockParent(hash string) bool {
return FAKE_AUXPOW_PREFORK_BLOCK_PARENTS[hash]
}

func init() {
MainNetParams = chaincfg.MainNetParams
MainNetParams.Net = MainnetMagic
MainNetParams.PubKeyHashAddrID = []byte{78}
MainNetParams.ScriptHashAddrID = []byte{60}
MainNetParams.Bech32HRPSegwit = "royale"
}

// BitcoinvaultParser handle
type BitcoinvaultParser struct {
*btc.BitcoinLikeParser
}

// NewBitcoinvaultParser returns new BitcoinvaultParser instance
func NewBitcoinvaultParser(params *chaincfg.Params, c *btc.Configuration) *BitcoinvaultParser {
return &BitcoinvaultParser{BitcoinLikeParser: btc.NewBitcoinLikeParser(params, c)}
}

// GetChainParams contains network parameters for the main Bitcoinvault network,
// and the test Bitcoinvault network
func GetChainParams(chain string) *chaincfg.Params {
if !chaincfg.IsRegistered(&MainNetParams) {
err := chaincfg.Register(&MainNetParams)
if err != nil {
panic(err)
}
}
switch chain {
default:
return &MainNetParams
}
}

// ParseBlock parses raw block to our Block struct
// it has special handling for Auxpow blocks that cannot be parsed by standard btc wire parser
func (p *BitcoinvaultParser) ParseBlock(b []byte) (*bchain.Block, error) {
r := bytes.NewReader(b)
w := wire.MsgBlock{}
h := wire.BlockHeader{}
err := h.Deserialize(r)

if err != nil {
return nil, err
}

if (h.Version & utils.VersionAuxpow) != 0 && !isFakeAuxpowPreforkBlockParent(h.PrevBlock.String()) {
if err = utils.SkipAuxpow(r); err != nil {
return nil, err
}
}

err = utils.DecodeTransactions(r, 0, wire.WitnessEncoding, &w)
if err != nil {
return nil, err
}

txs := make([]bchain.Tx, len(w.Transactions))
for ti, t := range w.Transactions {
txs[ti] = p.TxFromMsgTx(t, false)
}

return &bchain.Block{
BlockHeader: bchain.BlockHeader{
Size: len(b),
Time: h.Timestamp.Unix(),
},
Txs: txs,
}, nil
}
Loading