@@ -10,11 +10,13 @@ import (
1010	"github.com/sentinel-official/sentinel-go-sdk/utils" 
1111)
1212
13+ // RequestAddSession represents the request for adding a session. 
1314type  RequestAddSession  struct  {
1415	Data       []byte 
1516	PubKey     types.PubKey 
1617	Signature  []byte 
1718
19+ 	// Inline struct for the request body 
1820	Body  struct  {
1921		Data       string  `json:"data" binding:"required,base64,gt=0"` 
2022		ID         uint64  `json:"id" binding:"required,gt=0"` 
@@ -23,29 +25,39 @@ type RequestAddSession struct {
2325	}
2426}
2527
28+ // Msg generates the message from the session request. 
2629func  (r  * RequestAddSession ) Msg () []byte  {
27- 	return  append (cosmossdk .Uint64ToBigEndian (r .Body .ID ), r .Body . Data ... )
30+ 	return  append (cosmossdk .Uint64ToBigEndian (r .Body .ID ), r .Data ... )
2831}
2932
33+ // AccAddr returns the account address derived from the public key. 
34+ func  (r  * RequestAddSession ) AccAddr () cosmossdk.AccAddress  {
35+ 	return  r .PubKey .Address ().Bytes ()
36+ }
37+ 
38+ // newRequestAddSession binds and decodes the incoming request. 
3039func  newRequestAddSession (c  * gin.Context ) (req  * RequestAddSession , err  error ) {
3140	req  =  & RequestAddSession {}
3241	if  err  =  c .ShouldBindJSON (& req .Body ); err  !=  nil  {
3342		return  nil , fmt .Errorf ("failed to bind json body: %w" , err )
3443	}
3544
45+ 	// Decode base64 encoded data 
3646	req .Data , err  =  base64 .StdEncoding .DecodeString (req .Body .Data )
3747	if  err  !=  nil  {
38- 		return  nil , fmt .Errorf ("failed to decode data: %s " , err )
48+ 		return  nil , fmt .Errorf ("failed to decode data: %w " , err )
3949	}
4050
51+ 	// Decode base64 encoded signature 
4152	req .Signature , err  =  base64 .StdEncoding .DecodeString (req .Body .Signature )
4253	if  err  !=  nil  {
43- 		return  nil , fmt .Errorf ("failed to decode signature: %s " , err )
54+ 		return  nil , fmt .Errorf ("failed to decode signature: %w " , err )
4455	}
4556
57+ 	// Decode public key 
4658	req .PubKey , err  =  utils .DecodePubKey (req .Body .PubKey )
4759	if  err  !=  nil  {
48- 		return  nil , fmt .Errorf ("failed to decode pub_key: %s " , err )
60+ 		return  nil , fmt .Errorf ("failed to decode pub_key: %w " , err )
4961	}
5062
5163	return  req , nil 
0 commit comments