github.com/0chain/gosdk@v1.17.11/zcnbridge/authorizer_response.go (about)

     1  package zcnbridge
     2  
     3  import (
     4  	"encoding/json"
     5  	"errors"
     6  )
     7  
     8  type (
     9  	// JobStatus = Ethereum transaction status
    10  	JobStatus uint
    11  	// JobResult = Authorizer task result, it wraps actual result of the query inside authorizer
    12  	JobResult interface {
    13  		// Error = Status of Authorizer job on authorizer server
    14  		Error() error
    15  		// Data returns the actual result
    16  		Data() interface{}
    17  		// SetAuthorizerID Assigns authorizer ID to the Job
    18  		SetAuthorizerID(ID string)
    19  		// GetAuthorizerID returns authorizer ID
    20  		GetAuthorizerID() string
    21  	}
    22  	// JobError result of internal request wrapped in authorizer job
    23  	JobError struct {
    24  		error
    25  	}
    26  
    27  	// EthereumBurnEvents represents burn events returned by authorizers
    28  	EthereumBurnEvents struct {
    29  		AuthorizerID string `json:"authorizer_id,omitempty"`
    30  		BurnEvents   []struct {
    31  			Nonce           int64  `json:"nonce"`
    32  			Amount          int64  `json:"amount"`
    33  			TransactionHash string `json:"transaction_hash"`
    34  		} `json:"burn_events"`
    35  	}
    36  
    37  	// ProofEthereumBurn Authorizer returns this type for Ethereum transaction
    38  	ProofEthereumBurn struct {
    39  		TxnID             string `json:"ethereum_txn_id"`
    40  		Nonce             int64  `json:"nonce"`
    41  		Amount            int64  `json:"amount"`
    42  		ReceivingClientID string `json:"receiving_client_id"` // 0ZCN address
    43  		Signature         string `json:"signature"`
    44  	}
    45  
    46  	// ProofZCNBurn Authorizer returns this type for ZCN transaction
    47  	ProofZCNBurn struct {
    48  		AuthorizerID string `json:"authorizer_id,omitempty"`
    49  		TxnID        string `json:"0chain_txn_id"`
    50  		To           string `json:"to"`
    51  		Nonce        int64  `json:"nonce"`
    52  		Amount       int64  `json:"amount"`
    53  		Signature    []byte `json:"signature"`
    54  	}
    55  )
    56  
    57  func (e *JobError) UnmarshalJSON(buf []byte) error {
    58  	e.error = errors.New(string(buf))
    59  	return nil
    60  }
    61  
    62  func (e *JobError) MarshalJSON() ([]byte, error) {
    63  	return json.Marshal(e.Error())
    64  }
    65  
    66  // WZCNBurnEvent returned from burn ticket handler of: /v1/ether/burnticket/get
    67  type WZCNBurnEvent struct {
    68  	// 	AuthorizerID Authorizer ID
    69  	AuthorizerID string `json:"authorizer_id,omitempty"`
    70  	// BurnTicket Returns burn ticket
    71  	BurnTicket *ProofEthereumBurn `json:"ticket,omitempty"`
    72  	// Err gives error of job on server side
    73  	Err *JobError `json:"err,omitempty"`
    74  	// Status gives job status on server side (authoriser)
    75  	Status JobStatus `json:"status,omitempty"`
    76  }
    77  
    78  func (r *WZCNBurnEvent) GetAuthorizerID() string {
    79  	return r.AuthorizerID
    80  }
    81  
    82  func (r *WZCNBurnEvent) SetAuthorizerID(id string) {
    83  	r.AuthorizerID = id
    84  }
    85  
    86  func (r *WZCNBurnEvent) Error() error {
    87  	return r.Err
    88  }
    89  
    90  func (r *WZCNBurnEvent) Data() interface{} {
    91  	return r.BurnTicket
    92  }
    93  
    94  func (r *EthereumBurnEvents) GetAuthorizerID() string {
    95  	return r.AuthorizerID
    96  }
    97  
    98  func (r *EthereumBurnEvents) SetAuthorizerID(id string) {
    99  	r.AuthorizerID = id
   100  }
   101  
   102  func (r *EthereumBurnEvents) Error() error {
   103  	return nil
   104  }
   105  
   106  func (r *EthereumBurnEvents) Data() interface{} {
   107  	return r
   108  }
   109  
   110  func (r *ProofZCNBurn) GetAuthorizerID() string {
   111  	return r.AuthorizerID
   112  }
   113  
   114  func (r *ProofZCNBurn) SetAuthorizerID(id string) {
   115  	r.AuthorizerID = id
   116  }
   117  
   118  func (r *ProofZCNBurn) Error() error {
   119  	return nil
   120  }
   121  
   122  func (r *ProofZCNBurn) Data() interface{} {
   123  	return r
   124  }