github.com/Finschia/finschia-sdk@v0.48.1/server/rosetta/lib/internal/service/offline.go (about) 1 package service 2 3 import ( 4 "context" 5 6 "github.com/coinbase/rosetta-sdk-go/types" 7 8 crgerrs "github.com/Finschia/finschia-sdk/server/rosetta/lib/errors" 9 crgtypes "github.com/Finschia/finschia-sdk/server/rosetta/lib/types" 10 ) 11 12 // NewOffline instantiates the instance of an offline network 13 // whilst the offline network does not support the DataAPI, 14 // it supports a subset of the construction API. 15 func NewOffline(network *types.NetworkIdentifier, client crgtypes.Client) (crgtypes.API, error) { 16 return OfflineNetwork{ 17 OnlineNetwork{ 18 client: client, 19 network: network, 20 networkOptions: networkOptionsFromClient(client, nil), 21 }, 22 }, nil 23 } 24 25 // OfflineNetwork implements an offline data API 26 // which is basically a data API that constantly 27 // returns errors, because it cannot be used if offline 28 type OfflineNetwork struct { 29 OnlineNetwork 30 } 31 32 // Implement DataAPI in offline mode, which means no method is available 33 func (o OfflineNetwork) AccountBalance(_ context.Context, _ *types.AccountBalanceRequest) (*types.AccountBalanceResponse, *types.Error) { 34 return nil, crgerrs.ToRosetta(crgerrs.ErrOffline) 35 } 36 37 func (o OfflineNetwork) Block(_ context.Context, _ *types.BlockRequest) (*types.BlockResponse, *types.Error) { 38 return nil, crgerrs.ToRosetta(crgerrs.ErrOffline) 39 } 40 41 func (o OfflineNetwork) BlockTransaction(_ context.Context, _ *types.BlockTransactionRequest) (*types.BlockTransactionResponse, *types.Error) { 42 return nil, crgerrs.ToRosetta(crgerrs.ErrOffline) 43 } 44 45 func (o OfflineNetwork) Mempool(_ context.Context, _ *types.NetworkRequest) (*types.MempoolResponse, *types.Error) { 46 return nil, crgerrs.ToRosetta(crgerrs.ErrOffline) 47 } 48 49 func (o OfflineNetwork) MempoolTransaction(_ context.Context, _ *types.MempoolTransactionRequest) (*types.MempoolTransactionResponse, *types.Error) { 50 return nil, crgerrs.ToRosetta(crgerrs.ErrOffline) 51 } 52 53 func (o OfflineNetwork) NetworkStatus(_ context.Context, _ *types.NetworkRequest) (*types.NetworkStatusResponse, *types.Error) { 54 return nil, crgerrs.ToRosetta(crgerrs.ErrOffline) 55 } 56 57 func (o OfflineNetwork) ConstructionSubmit(_ context.Context, _ *types.ConstructionSubmitRequest) (*types.TransactionIdentifierResponse, *types.Error) { 58 return nil, crgerrs.ToRosetta(crgerrs.ErrOffline) 59 } 60 61 func (o OfflineNetwork) ConstructionMetadata(_ context.Context, _ *types.ConstructionMetadataRequest) (*types.ConstructionMetadataResponse, *types.Error) { 62 return nil, crgerrs.ToRosetta(crgerrs.ErrOffline) 63 }