Skip to content

Commit 55a2806

Browse files
authored
Merge pull request #40 from renproject/feat/native-asset
Feat/native asset
2 parents 90f479a + 3d6588b commit 55a2806

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

multichain.go

+45-5
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const (
112112
LUNA = Asset("LUNA") // Luna
113113
ZEC = Asset("ZEC") // Zcash
114114

115-
// These assets are define separately because they are mock assets. These
115+
// These assets are defined separately because they are mock assets. These
116116
// assets should only be used for testing.
117117

118118
AMOCK1 = Asset("AMOCK1") // Account-based mock asset
@@ -149,7 +149,7 @@ func (asset Asset) OriginChain() Chain {
149149
case ZEC:
150150
return Zcash
151151

152-
// These assets are define separately because they are mock assets. These
152+
// These assets are handled separately because they are mock assets. These
153153
// assets should only be used for testing.
154154

155155
case AMOCK1:
@@ -172,8 +172,9 @@ func (asset Asset) ChainType() ChainType {
172172
case BNB, ETH, FIL, LUNA:
173173
return ChainTypeAccountBased
174174

175-
// These assets are define separately because they are mock assets. These
175+
// These assets are handled separately because they are mock assets. These
176176
// assets should only be used for testing.
177+
177178
case AMOCK1, AMOCK2:
178179
return ChainTypeAccountBased
179180
case UMOCK:
@@ -221,7 +222,7 @@ const (
221222
Terra = Chain("Terra")
222223
Zcash = Chain("Zcash")
223224

224-
// These chains are define separately because they are mock chains. These
225+
// These chains are defined separately because they are mock chains. These
225226
// chains should only be used for testing.
226227

227228
AccountMocker1 = Chain("AccountMocker1")
@@ -256,8 +257,9 @@ func (chain Chain) ChainType() ChainType {
256257
case BinanceSmartChain, Ethereum, Filecoin, Terra:
257258
return ChainTypeAccountBased
258259

259-
// These chains are define separately because they are mock chains. These
260+
// These chains are handled separately because they are mock chains. These
260261
// chains should only be used for testing.
262+
261263
case AccountMocker1, AccountMocker2:
262264
return ChainTypeAccountBased
263265
case UTXOMocker:
@@ -280,6 +282,44 @@ func (chain Chain) IsUTXOBased() bool {
280282
return chain.ChainType() == ChainTypeUTXOBased
281283
}
282284

285+
// NativeAsset returns the underlying native asset for a chain. For example, the
286+
// root asset of Bitcoin chain is BTC.
287+
func (chain Chain) NativeAsset() Asset {
288+
switch chain {
289+
case BinanceSmartChain:
290+
return BNB
291+
case BitcoinCash:
292+
return BCH
293+
case Bitcoin:
294+
return BTC
295+
case DigiByte:
296+
return DGB
297+
case Dogecoin:
298+
return DOGE
299+
case Ethereum:
300+
return ETH
301+
case Filecoin:
302+
return FIL
303+
case Terra:
304+
return LUNA
305+
case Zcash:
306+
return ZEC
307+
308+
// These chains are handled separately because they are mock chains. These
309+
// chains should only be used for testing.
310+
311+
case AccountMocker1:
312+
return AMOCK1
313+
case AccountMocker2:
314+
return AMOCK2
315+
case UTXOMocker:
316+
return UMOCK
317+
318+
default:
319+
return Asset("")
320+
}
321+
}
322+
283323
// ChainType represents the type of chain (whether account-based or utxo-based)
284324
type ChainType string
285325

0 commit comments

Comments
 (0)