github.com/status-im/status-go@v1.1.0/mobile/types.go (about)

     1  package statusgo
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  	"strings"
     7  )
     8  
     9  // APIResponse generic response from API.
    10  type APIResponse struct {
    11  	Error string `json:"error"`
    12  }
    13  
    14  // APIKeyUIDResponse
    15  type APIKeyUIDResponse struct {
    16  	KeyUID string `json:"keyUID"`
    17  }
    18  
    19  // APIDetailedResponse represents a generic response
    20  // with possible errors.
    21  type APIDetailedResponse struct {
    22  	Status      bool            `json:"status"`
    23  	Message     string          `json:"message,omitempty"`
    24  	FieldErrors []APIFieldError `json:"field_errors,omitempty"`
    25  }
    26  
    27  // Error string representation of APIDetailedResponse.
    28  func (r APIDetailedResponse) Error() string {
    29  	buf := bytes.NewBufferString("")
    30  
    31  	for _, err := range r.FieldErrors {
    32  		buf.WriteString(err.Error() + "\n") // nolint: gas
    33  	}
    34  
    35  	return strings.TrimSpace(buf.String())
    36  }
    37  
    38  // APIFieldError represents a set of errors
    39  // related to a parameter.
    40  type APIFieldError struct {
    41  	Parameter string     `json:"parameter,omitempty"`
    42  	Errors    []APIError `json:"errors"`
    43  }
    44  
    45  // Error string representation of APIFieldError.
    46  func (e APIFieldError) Error() string {
    47  	if len(e.Errors) == 0 {
    48  		return ""
    49  	}
    50  
    51  	buf := bytes.NewBufferString(fmt.Sprintf("Parameter: %s\n", e.Parameter))
    52  
    53  	for _, err := range e.Errors {
    54  		buf.WriteString(err.Error() + "\n") // nolint: gas
    55  	}
    56  
    57  	return strings.TrimSpace(buf.String())
    58  }
    59  
    60  // APIError represents a single error.
    61  type APIError struct {
    62  	Message string `json:"message"`
    63  }
    64  
    65  // Error string representation of APIError.
    66  func (e APIError) Error() string {
    67  	return fmt.Sprintf("message=%s", e.Message)
    68  }
    69  
    70  // AccountInfo represents account's info.
    71  type AccountInfo struct {
    72  	Address       string `json:"address"` // DEPRECATED
    73  	PubKey        string `json:"pubkey"`  // DEPRECATED
    74  	WalletAddress string `json:"walletAddress"`
    75  	WalletPubKey  string `json:"walletPubKey"`
    76  	ChatAddress   string `json:"chatAddress"`
    77  	ChatPubKey    string `json:"chatPubKey"`
    78  	Mnemonic      string `json:"mnemonic"`
    79  	Error         string `json:"error"`
    80  }
    81  
    82  // OnboardingAccount represents accounts info generated for the onboarding.
    83  type OnboardingAccount struct {
    84  	ID            string `json:"id"`
    85  	Address       string `json:"address"` // DEPRECATED
    86  	PubKey        string `json:"pubkey"`  // DEPRECATED
    87  	WalletAddress string `json:"walletAddress"`
    88  	WalletPubKey  string `json:"walletPubKey"`
    89  	ChatAddress   string `json:"chatAddress"`
    90  	ChatPubKey    string `json:"chatPubKey"`
    91  }
    92  
    93  // NotifyResult is a JSON returned from notify message.
    94  type NotifyResult struct {
    95  	Status bool   `json:"status"`
    96  	Error  string `json:"error,omitempty"`
    97  }
    98  
    99  // SignalHandler defines a minimal interface
   100  // a signal handler needs to implement.
   101  type SignalHandler interface {
   102  	HandleSignal(string)
   103  }