forked from nami-land/walleter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommandparser.go
78 lines (70 loc) · 2.37 KB
/
commandparser.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
package walleter
import (
"gorm.io/gorm"
)
// parseCommandToERC20WalletArray convert erc20command array to erc20TokenWallet Array.
func parseCommandToERC20WalletArray(command WalletCommand) []ERC20TokenWallet {
var result []ERC20TokenWallet
for _, item := range command.ERC20Commands {
data := ERC20TokenWallet{
Model: gorm.Model{},
AccountId: command.AccountId,
Token: item.Token.String(),
Decimal: item.Decimal,
}
result = append(result, data)
}
return result
}
func parseCommandToERC1155Wallet(command WalletCommand) ERC1155TokenWallet {
return ERC1155TokenWallet{
Model: gorm.Model{},
AccountId: command.AccountId,
Ids: convertArrayToString(command.ERC1155Command.Ids, ","),
Values: convertArrayToString(command.ERC1155Command.Values, ","),
}
}
func parseCommandToERC20WalletLog(command WalletCommand, w Wallet) ERC20WalletLog {
fees := parseERC20Commands(command.FeeCommands)
gonnaChangedTokens := parseERC20Commands(command.ERC20Commands)
return ERC20WalletLog{
Model: gorm.Model{},
AccountId: command.AccountId,
BusinessModule: command.BusinessModule,
ActionType: command.ActionType.String(),
Tokens: erc20TokenCollection{Items: gonnaChangedTokens},
Fees: erc20TokenCollection{Items: fees},
Status: Pending.String(),
OriginalWallet: w,
Source: command.CommandSource.String(),
SettledWallet: Wallet{},
}
}
func parseCommandToERC1155WalletLog(command WalletCommand, w Wallet) ERC1155WalletLog {
fees := parseERC20Commands(command.FeeCommands)
return ERC1155WalletLog{
Model: gorm.Model{},
AccountId: command.AccountId,
BusinessModule: command.BusinessModule,
ActionType: command.ActionType.String(),
Ids: convertArrayToString(command.ERC1155Command.Ids, ","),
Values: convertArrayToString(command.ERC1155Command.Values, ","),
Fees: erc20TokenCollection{Items: fees},
Status: Pending.String(),
Source: command.CommandSource.String(),
OriginalWallet: w,
SettledWallet: Wallet{},
}
}
func parseERC20Commands(commands []ERC20Command) []erc20TokenData {
var result []erc20TokenData
for _, data := range commands {
tokenData := erc20TokenData{
TokenType: data.Token.String(),
Amount: data.Value,
Decimal: data.Decimal,
}
result = append(result, tokenData)
}
return result
}