@@ -51,58 +51,95 @@ func NewContext() *Context {
5151	}
5252}
5353
54+ // checkSealed verifies if the context is sealed to prevent modification. 
55+ func  (c  * Context ) checkSealed () {
56+ 	if  c .sealed  {
57+ 		panic (errors .New ("context is sealed" ))
58+ 	}
59+ }
60+ 
61+ // Seal marks the context as sealed, preventing further modifications. 
62+ func  (c  * Context ) Seal () * Context  {
63+ 	c .sealed  =  true 
64+ 	return  c 
65+ }
66+ 
5467// AccAddr returns the transaction sender address set in the context. 
5568func  (c  * Context ) AccAddr () cosmossdk.AccAddress  {
69+ 	c .fm .RLock ()
70+ 	defer  c .fm .RUnlock ()
5671	return  c .accAddr .Bytes ()
5772}
5873
5974// APIAddrs returns the api addresses set in the context. 
6075func  (c  * Context ) APIAddrs () []string  {
76+ 	c .fm .RLock ()
77+ 	defer  c .fm .RUnlock ()
6178	return  c .apiAddrs 
6279}
6380
6481// APIListenAddr returns the listen address of the node API. 
6582func  (c  * Context ) APIListenAddr () string  {
83+ 	c .fm .RLock ()
84+ 	defer  c .fm .RUnlock ()
6685	return  c .apiListenAddr 
6786}
6887
6988// Client returns the client instance set in the context. 
7089func  (c  * Context ) Client () * core.Client  {
71- 	return  c .client .WithRPCAddr (c .RPCAddr ()) // TODO: is it needed? 
90+ 	c .fm .RLock ()
91+ 	defer  c .fm .RUnlock ()
92+ 
93+ 	c .client .SetRPCAddr (c .RPCAddr ())
94+ 	return  c .client 
7295}
7396
7497// Database returns the database connection set in the context. 
7598func  (c  * Context ) Database () * gorm.DB  {
99+ 	c .fm .RLock ()
100+ 	defer  c .fm .RUnlock ()
76101	return  c .database 
77102}
78103
79104// DatabaseFile returns the database path of the node. 
80105func  (c  * Context ) DatabaseFile () string  {
106+ 	c .fm .RLock ()
107+ 	defer  c .fm .RUnlock ()
81108	return  filepath .Join (c .HomeDir (), "data.db" )
82109}
83110
84111// GeoIPClient returns the GeoIP client set in the context. 
85112func  (c  * Context ) GeoIPClient () geoip.Client  {
113+ 	c .fm .RLock ()
114+ 	defer  c .fm .RUnlock ()
86115	return  c .geoIPClient 
87116}
88117
89118// GigabytePrices returns the gigabyte prices for nodes. 
90119func  (c  * Context ) GigabytePrices () v1.Prices  {
120+ 	c .fm .RLock ()
121+ 	defer  c .fm .RUnlock ()
91122	return  c .gigabytePrices 
92123}
93124
94125// HomeDir returns the home directory set in the context. 
95126func  (c  * Context ) HomeDir () string  {
127+ 	c .fm .RLock ()
128+ 	defer  c .fm .RUnlock ()
96129	return  c .homeDir 
97130}
98131
99132// HourlyPrices returns the hourly prices for nodes. 
100133func  (c  * Context ) HourlyPrices () v1.Prices  {
134+ 	c .fm .RLock ()
135+ 	defer  c .fm .RUnlock ()
101136	return  c .hourlyPrices 
102137}
103138
104139// Input returns the keyring input set in the context. 
105140func  (c  * Context ) Input () io.Reader  {
141+ 	c .fm .RLock ()
142+ 	defer  c .fm .RUnlock ()
106143	return  c .input 
107144}
108145
@@ -115,27 +152,38 @@ func (c *Context) Location() *geoip.Location {
115152
116153// MaxPeers returns the maximum peers for the service. 
117154func  (c  * Context ) MaxPeers () uint  {
155+ 	c .fm .RLock ()
156+ 	defer  c .fm .RUnlock ()
118157	return  c .maxPeers 
119158}
120159
121160// Moniker returns the name or identifier for the node. 
122161func  (c  * Context ) Moniker () string  {
162+ 	c .fm .RLock ()
163+ 	defer  c .fm .RUnlock ()
123164	return  c .moniker 
124165}
125166
126167func  (c  * Context ) NodeAddr () sentinelhub.NodeAddress  {
168+ 	c .fm .RLock ()
169+ 	defer  c .fm .RUnlock ()
127170	return  c .accAddr .Bytes ()
128171}
129172
130173// RemoteAddrs returns the remote addresses set in the context. 
131174func  (c  * Context ) RemoteAddrs () []string  {
175+ 	c .fm .RLock ()
176+ 	defer  c .fm .RUnlock ()
132177	return  c .remoteAddrs 
133178}
134179
135180// RPCAddr returns the first RPC address from the list or an empty string if no addresses are available. 
136181func  (c  * Context ) RPCAddr () string  {
182+ 	c .fm .RLock ()
183+ 	defer  c .fm .RUnlock ()
184+ 
137185	addrs  :=  c .RPCAddrs ()
138- 	if  len (addrs ) ==  0  { // TODO: is it needed ? 
186+ 	if  len (addrs ) ==  0  { // TODO: remove this ? 
139187		return  "" 
140188	}
141189
@@ -149,24 +197,31 @@ func (c *Context) RPCAddrs() []string {
149197	return  c .rpcAddrs 
150198}
151199
152- // Seal marks the context as sealed, preventing further modifications. 
153- func  (c  * Context ) Seal () * Context  {
154- 	c .sealed  =  true 
155- 	return  c 
156- }
157- 
158200// Service returns the server service instance set in the context. 
159201func  (c  * Context ) Service () sentinelsdk.ServerService  {
202+ 	c .fm .RLock ()
203+ 	defer  c .fm .RUnlock ()
160204	return  c .service 
161205}
162206
207+ // SpeedtestResults returns the download and upload speeds set in the context. 
208+ func  (c  * Context ) SpeedtestResults () (dlSpeed , ulSpeed  math.Int ) {
209+ 	c .fm .RLock ()
210+ 	defer  c .fm .RUnlock ()
211+ 	return  c .dlSpeed , c .ulSpeed 
212+ }
213+ 
163214// TLSCertFile returns the TLS certificate path of the node API server. 
164215func  (c  * Context ) TLSCertFile () string  {
216+ 	c .fm .RLock ()
217+ 	defer  c .fm .RUnlock ()
165218	return  filepath .Join (c .HomeDir (), "tls.crt" )
166219}
167220
168221// TLSKeyFile returns the TLS key path of the node API server. 
169222func  (c  * Context ) TLSKeyFile () string  {
223+ 	c .fm .RLock ()
224+ 	defer  c .fm .RUnlock ()
170225	return  filepath .Join (c .HomeDir (), "tls.key" )
171226}
172227
@@ -192,13 +247,6 @@ func (c *Context) SetSpeedtestResults(dlSpeed, ulSpeed math.Int) {
192247	c .ulSpeed  =  ulSpeed 
193248}
194249
195- // SpeedtestResults returns the download and upload speeds set in the context. 
196- func  (c  * Context ) SpeedtestResults () (dlSpeed , ulSpeed  math.Int ) {
197- 	c .fm .RLock ()
198- 	defer  c .fm .RUnlock ()
199- 	return  c .dlSpeed , c .ulSpeed 
200- }
201- 
202250// WithAccAddr sets the transaction sender address in the context and returns the updated context. 
203251func  (c  * Context ) WithAccAddr (addr  cosmossdk.AccAddress ) * Context  {
204252	c .checkSealed ()
@@ -303,10 +351,3 @@ func (c *Context) WithService(service sentinelsdk.ServerService) *Context {
303351	c .service  =  service 
304352	return  c 
305353}
306- 
307- // checkSealed verifies if the context is sealed to prevent modification. 
308- func  (c  * Context ) checkSealed () {
309- 	if  c .sealed  {
310- 		panic (errors .New ("context is sealed" ))
311- 	}
312- }
0 commit comments