-
Notifications
You must be signed in to change notification settings - Fork 1
/
contracts.go
68 lines (54 loc) · 2.23 KB
/
contracts.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
// Package contracts provide golang functions to read smart-contracts of snet-ecosystem
package contracts
import (
"bytes"
"embed"
)
type SnetContract string
const SingularityNetToken SnetContract = "SingularityNetToken"
const MultiPartyEscrow SnetContract = "MultiPartyEscrow"
const Registry SnetContract = "Registry"
const TokenStake SnetContract = "TokenStake"
const TokenConversionManager SnetContract = "TokenConversionManager"
var List = []SnetContract{SingularityNetToken, MultiPartyEscrow, Registry, TokenStake, TokenConversionManager}
//go:embed snet/contracts/resources/abi/*.json
var abifs embed.FS
//go:embed snet/contracts/resources/bytecode/*.json
var bytecodefs embed.FS
//go:embed snet/contracts/resources/networks/*.json
var networksfs embed.FS
func GetABI(name SnetContract) (content []byte) {
content, _ = abifs.ReadFile("snet/contracts/resources/abi/" + string(name) + ".json")
return content
}
// GetABIClean returns content without spaces and line breaks
func GetABIClean(name SnetContract) (content []byte) {
return removeSpecialChars(GetABI(name))
}
func GetBytecode(name SnetContract) (content []byte) {
content, _ = bytecodefs.ReadFile("snet/contracts/resources/bytecode/" + string(name) + ".json")
return content
}
// GetBytecodeClean returns content without double quotes, spaces and line breaks
func GetBytecodeClean(name SnetContract) (content []byte) {
result := bytes.ReplaceAll(GetBytecode(name), []byte(`"`), []byte(""))
return removeSpecialChars(result)
}
// get addresses, events, and more for smart contracts for different networks
func GetNetworks(name SnetContract) (content []byte) {
if name == TokenConversionManager {
return
}
content, _ = networksfs.ReadFile("snet/contracts/resources/networks/" + string(name) + ".json")
return content
}
// GetNetworksClean returns networks without spaces and line breaks
func GetNetworksClean(name SnetContract) (content []byte) {
return removeSpecialChars(GetNetworks(name))
}
func removeSpecialChars(content []byte) []byte {
result := bytes.ReplaceAll(content, []byte(` `), []byte(""))
result = bytes.ReplaceAll(result, []byte(`\n`), []byte(""))
result = bytes.ReplaceAll(result, []byte(`\r`), []byte(""))
return bytes.ReplaceAll(result, []byte(`\t`), []byte(""))
}