-
Notifications
You must be signed in to change notification settings - Fork 1
/
multichain.go
159 lines (142 loc) · 4.37 KB
/
multichain.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Package multichain defines all supported assets and chains. It also
// re-exports the individual multichain APIs.
package multichain
import (
"github.com/renproject/multichain/api/account"
"github.com/renproject/multichain/api/address"
"github.com/renproject/multichain/api/contract"
"github.com/renproject/multichain/api/gas"
"github.com/renproject/multichain/api/utxo"
"github.com/renproject/multichain/chain/ethereum"
"github.com/renproject/surge"
)
type (
Address = address.Address
AddressEncodeDecoder = address.EncodeDecoder
EthereumCompatAddress = ethereum.Address
RawAddress = address.RawAddress
)
type (
AccountTx = account.Tx
AccountTxBuilder = account.TxBuilder
AccountClient = account.Client
)
type (
UTXOutpoint = utxo.Outpoint
UTXOutput = utxo.Output
UTXOInput = utxo.Input
UTXORecipient = utxo.Recipient
UTXOTx = utxo.Tx
UTXOTxBuilder = utxo.TxBuilder
UTXOClient = utxo.Client
)
type (
ContractCallData = contract.CallData
ContractCaller = contract.Caller
)
type (
GasEstimator = gas.Estimator
)
// An Asset uniquely identifies assets using human-readable strings.
type Asset string
// Enumeration of supported assets. When introducing a new chain, or new asset
// from an existing chain, you must add a human-readable string to this set of
// enumerated values. Assets must be listed in alphabetical order.
const (
BCH = Asset("BCH") // Bitcoin Cash
BNB = Asset("BNB") // Binance Coin
BTC = Asset("BTC") // Bitcoin
CELO = Asset("CELO") // Celo
CRW = Asset("CRW") // Crown
DGB = Asset("DGB") // DigiByte
DOGE = Asset("DOGE") // Dogecoin
ETH = Asset("ETH") // Ether
FIL = Asset("FIL") // Filecoin
FTM = Asset("FTM") // Fantom
SOL = Asset("SOL") // Solana
LUNA = Asset("LUNA") // Luna
ZEC = Asset("ZEC") // Zcash
)
// OriginChain returns the chain upon which the asset originates. For example,
// the origin chain of BTC is Bitcoin.
func (asset Asset) OriginChain() Chain {
switch asset {
case BCH:
return BitcoinCash
case BNB:
return BinanceSmartChain
case BTC:
return Bitcoin
case CELO:
return Celo
case CRW:
return Crown
case DGB:
return DigiByte
case DOGE:
return Dogecoin
case ETH:
return Ethereum
case FIL:
return Filecoin
case FTM:
return Fantom
case LUNA:
return Terra
case SOL:
return Solana
case ZEC:
return Zcash
default:
return Chain("")
}
}
// SizeHint returns the number of bytes required to represent the asset in
// binary.
func (asset Asset) SizeHint() int {
return surge.SizeHintString(string(asset))
}
// Marshal the asset to binary.
func (asset Asset) Marshal(buf []byte, rem int) ([]byte, int, error) {
return surge.MarshalString(string(asset), buf, rem)
}
// Unmarshal the asset from binary.
func (asset *Asset) Unmarshal(buf []byte, rem int) ([]byte, int, error) {
return surge.UnmarshalString((*string)(asset), buf, rem)
}
// A Chain uniquely identifies a blockchain using a human-readable string.
type Chain string
// Enumeration of supported chains. When introducing a new chain, you must add a
// human-readable string to this set of enumerated values. Chains must be listed
// in alphabetical order.
const (
Acala = Chain("Acala")
BinanceSmartChain = Chain("BinanceSmartChain")
Bitcoin = Chain("Bitcoin")
BitcoinCash = Chain("BitcoinCash")
Celo = Chain("Celo")
Crown = Chain("Crown")
DigiByte = Chain("DigiByte")
Dogecoin = Chain("Dogecoin")
Ethereum = Chain("Ethereum")
Fantom = Chain("Fantom")
Filecoin = Chain("Filecoin")
Solana = Chain("Solana")
Terra = Chain("Terra")
Zcash = Chain("Zcash")
)
// SizeHint returns the number of bytes required to represent the chain in
// binary.
func (chain Chain) SizeHint() int {
return surge.SizeHintString(string(chain))
}
// Marshal the chain to binary. You should not call this function directly,
// unless you are implementing marshalling for a container type.
func (chain Chain) Marshal(buf []byte, rem int) ([]byte, int, error) {
return surge.MarshalString(string(chain), buf, rem)
}
// Unmarshal the chain from binary. You should not call this function directly,
// unless you are implementing unmarshalling for a container type.
func (chain *Chain) Unmarshal(buf []byte, rem int) ([]byte, int, error) {
return surge.UnmarshalString((*string)(chain), buf, rem)
}