-
Notifications
You must be signed in to change notification settings - Fork 47
/
omni.go
63 lines (53 loc) · 1.63 KB
/
omni.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package omni
import (
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcutil/hdkeychain"
"github.com/dabankio/wallet-core/bip44"
"github.com/dabankio/wallet-core/core"
"github.com/dabankio/wallet-core/core/btc"
"github.com/pkg/errors"
)
const (
symbol = "OMNI"
// MinNondustOutput Any standard (ie P2PKH) output smaller than this value (in satoshis) will most likely be rejected by the network.
// This is calculated by assuming a standard output will be 34 bytes
MinNondustOutput = 546 // satoshis
omniHex = "6f6d6e69" // Hex-encoded: "omni"
OptionShareAccountWithParentChain = "shareAccountWithParentChain"
)
var _ core.Coin = &omni{}
var _ core.HasParentChain = &omni{}
type omni struct {
btc.Btc
}
func New(seed []byte, testNet bool) (c *omni, err error) {
return nil, errors.New("该函数已废弃,请使用 NewWithOptions 替换")
}
func NewWithOptions(path string, seed []byte, testNet bool, options map[string]interface{}) (c *omni, err error) {
c = new(omni)
c.Symbol = symbol
bip44Key := symbol
if _, ok := options[OptionShareAccountWithParentChain]; ok {
bip44Key = c.GetParentChainName()
}
bip44ID, err := bip44.GetCoinType(bip44Key)
if err != nil {
return nil, err
}
c.DerivationPath, err = bip44.GetDerivePath(path, bip44ID, nil)
if err != nil {
return nil, errors.Wrap(err, "bip44.GetDerivePath err:")
}
c.ChainCfg = &chaincfg.MainNetParams
if testNet {
c.ChainCfg = &chaincfg.TestNet3Params
}
c.MasterKey, err = hdkeychain.NewMaster(seed, c.ChainCfg)
if err != nil {
return
}
return
}
func (*omni) GetParentChainName() string {
return core.ParentChainCofnig[symbol]
}