-
Notifications
You must be signed in to change notification settings - Fork 115
/
asset.go
60 lines (50 loc) · 1.7 KB
/
asset.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
package wallet
import (
"github.com/capossele/asset-registry/pkg/registry"
"github.com/cockroachdb/errors"
"github.com/iotaledger/goshimmer/packages/ledgerstate"
)
// Asset represents a container for all the information regarding a colored coin.
type Asset struct {
// Color contains the identifier of this asset
Color ledgerstate.Color
// Name of the asset
Name string
// currency symbol of the asset (optional)
Symbol string
// Precision defines how many decimal places are shown when showing this asset in wallets
Precision int
// Supply is the amount of tokens that we want to create
Supply uint64
// TransactionID that created the asset
TransactionID ledgerstate.TransactionID
}
// ToRegistry creates a ergistry asset from a wallet asset.
func (a *Asset) ToRegistry() *registry.Asset {
return ®istry.Asset{
ID: a.Color.Base58(),
Name: a.Name,
Symbol: a.Symbol,
Supply: a.Supply,
TransactionID: a.TransactionID.Base58(),
}
}
// AssetFromRegistryEntry creates a wallet asset from a registry asset.
func AssetFromRegistryEntry(regAsset *registry.Asset) (*Asset, error) {
color, err := ledgerstate.ColorFromBase58EncodedString(regAsset.ID)
if err != nil {
return nil, errors.Errorf("failed to parse color(ID) of asset from registry response: %w, err")
}
var txID ledgerstate.TransactionID
txID, err = ledgerstate.TransactionIDFromBase58(regAsset.TransactionID)
if err != nil {
return nil, errors.Errorf("failed to parse TransactionID of asset from registry response: %w, err")
}
return &Asset{
Color: color,
Name: regAsset.Name,
Symbol: regAsset.Symbol,
Supply: regAsset.Supply,
TransactionID: txID,
}, nil
}