Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default address encodings for Bitcoin #50

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions bitcoin/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,35 +85,53 @@ const (
P2PKHScriptPubkeySize = 25 // P2PKH size
)

// CreateMainNetParams is a function to override default mainnet settings with address prefixes
func CreateMainNetParams() (*chaincfg.Params) {
Copy link
Contributor

@patrick-ogrady patrick-ogrady Dec 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sidhujag would it make more sense to provide a JSON file at initialization that determines the values of chaincfg.Params? If not provided, it would just default to what we already had here.

In the general case, I think this would mean that a fork could integrate without maintaining their own repo? Unless you've seen other things that must be changed?

Copy link
Contributor Author

@sidhujag sidhujag Dec 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup that makes sense. Outside of these network changes and the overriding of the default table/log sizes for badger we should be able to just use rosetta-bitcoin. I actually prefer this option. If we can move it out to json then we can configure network settings, the genesis details, the address prefixes and it should just work.

See syscoin#1 for related issue, the CLI also needs configurable setting for the badger log/table defaults. Other than that it is common with the base.

params := &chaincfg.MainNetParams
params.PubKeyHashAddrID = 0
params.ScriptHashAddrID = 5
params.Bech32HRPSegwit = "bc"
return params
}

// CreateTestNet3Params is a function to override default testnet settings with address prefixes
func CreateTestNet3Params() (*chaincfg.Params) {
params := &chaincfg.TestNet3Params
params.PubKeyHashAddrID = 111
params.ScriptHashAddrID = 196
params.Bech32HRPSegwit = "tb"
return params
}

var (
// MainnetGenesisBlockIdentifier is the genesis block for mainnet.
MainnetGenesisBlockIdentifier = &types.BlockIdentifier{
Hash: "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
}

// MainnetParams are the params for mainnet.
MainnetParams = &chaincfg.MainNetParams
MainnetParams = CreateMainNetParams()

// MainnetCurrency is the *types.Currency for mainnet.
MainnetCurrency = &types.Currency{
Symbol: "BTC",
Decimals: Decimals,
}

// TestnetGenesisBlockIdentifier is the genesis block for testnet.
TestnetGenesisBlockIdentifier = &types.BlockIdentifier{
Hash: "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943",
}

// TestnetParams are the params for testnet.
TestnetParams = &chaincfg.TestNet3Params
TestnetParams = CreateTestNet3Params()

// TestnetCurrency is the *types.Currency for testnet.
TestnetCurrency = &types.Currency{
Symbol: "tBTC",
Decimals: Decimals,
}

// OperationTypes are all supported operation.Types.
OperationTypes = []string{
InputOpType,
Expand Down