github.com/0chain/gosdk@v1.17.11/zmagmacore/node/self.go (about) 1 // DEPRECATED: This package is deprecated and will be removed in a future release. 2 package node 3 4 import ( 5 "net/url" 6 "strconv" 7 "time" 8 9 "github.com/0chain/gosdk/zmagmacore/wallet" 10 ) 11 12 // Node represent self node type. 13 type Node struct { 14 url string 15 wallet *wallet.Wallet 16 extID string 17 startTime time.Time 18 } 19 20 var ( 21 self = &Node{} 22 ) 23 24 // Start writes to self node current time, sets wallet, external id and url 25 // 26 // Start should be used only once while application is starting. 27 func Start(host string, port int, extID string, wallet *wallet.Wallet) { 28 self = &Node{ 29 url: makeHostURL(host, port), 30 wallet: wallet, 31 extID: extID, 32 startTime: time.Now(), 33 } 34 } 35 36 func makeHostURL(host string, port int) string { 37 if host == "" { 38 host = "localhost" 39 } 40 41 uri := url.URL{ 42 Scheme: "http", 43 Host: host + ":" + strconv.Itoa(port), 44 } 45 46 return uri.String() 47 } 48 49 // GetWalletString returns marshaled to JSON string nodes wallet. 50 func GetWalletString() (string, error) { 51 return self.wallet.StringJSON() 52 } 53 54 func SetWallet(wall *wallet.Wallet) { 55 self.wallet = wall 56 } 57 58 // ID returns id of Node. 59 func ID() string { 60 return self.wallet.ID() 61 } 62 63 func ExtID() string { 64 return self.extID 65 } 66 67 // PublicKey returns id of Node. 68 func PublicKey() string { 69 return self.wallet.PublicKey() 70 } 71 72 // PrivateKey returns id of Node. 73 func PrivateKey() string { 74 return self.wallet.PrivateKey() 75 } 76 77 // StartTime returns time when Node is started. 78 func StartTime() time.Time { 79 return self.startTime 80 }