code.vegaprotocol.io/vega@v0.79.0/datanode/entities/oracle_spec.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package entities
    17  
    18  import (
    19  	"time"
    20  
    21  	v2 "code.vegaprotocol.io/vega/protos/data-node/api/v2"
    22  	vegapb "code.vegaprotocol.io/vega/protos/vega"
    23  )
    24  
    25  type OracleSpec struct {
    26  	ExternalDataSourceSpec *ExternalDataSourceSpec
    27  }
    28  
    29  func OracleSpecFromProto(spec *vegapb.OracleSpec, txHash TxHash, vegaTime time.Time) *OracleSpec {
    30  	if spec != nil {
    31  		if spec.ExternalDataSourceSpec != nil {
    32  			ds := ExternalDataSourceSpecFromProto(spec.ExternalDataSourceSpec, txHash, vegaTime)
    33  
    34  			return &OracleSpec{
    35  				ExternalDataSourceSpec: ds,
    36  			}
    37  		}
    38  	}
    39  
    40  	return &OracleSpec{
    41  		ExternalDataSourceSpec: &ExternalDataSourceSpec{},
    42  	}
    43  }
    44  
    45  func (os OracleSpec) ToProto() *vegapb.OracleSpec {
    46  	return &vegapb.OracleSpec{
    47  		ExternalDataSourceSpec: os.ExternalDataSourceSpec.ToProto(),
    48  	}
    49  }
    50  
    51  func (os OracleSpec) Cursor() *Cursor {
    52  	return NewCursor(DataSourceSpecCursor{os.ExternalDataSourceSpec.Spec.VegaTime, os.ExternalDataSourceSpec.Spec.ID}.String())
    53  }
    54  
    55  func (os OracleSpec) ToProtoEdge(_ ...any) (*v2.OracleSpecEdge, error) {
    56  	return &v2.OracleSpecEdge{
    57  		Node:   os.ToProto(),
    58  		Cursor: os.Cursor().Encode(),
    59  	}, nil
    60  }