forked from trezor/blockbook
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'guarda-changes' into master
- Loading branch information
Showing
49 changed files
with
2,885 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.BitcoinParser | ||
} | ||
|
||
// NewAryaCoinParser returns new AryaCoinParser instance | ||
func NewAryaCoinParser(params *chaincfg.Params, c *btc.Configuration) *AryaCoinParser { | ||
return &AryaCoinParser{BitcoinParser: btc.NewBitcoinParser(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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.