Documentation ¶
Index ¶
- Constants
- Variables
- func LoggerMiddleware(loggerRaw *zap.Logger, inner http.Handler) http.Handler
- func NewAccountAPIService(config *configuration.Configuration, i Indexer) server.AccountAPIServicer
- func NewBlockAPIService(config *configuration.Configuration, i Indexer) server.BlockAPIServicer
- func NewBlockchainRouter(config *configuration.Configuration, client Client, i Indexer, ...) http.Handler
- func NewConstructionAPIService(config *configuration.Configuration, client Client, i Indexer) server.ConstructionAPIServicer
- func NewMempoolAPIService(config *configuration.Configuration, client Client) server.MempoolAPIServicer
- func NewNetworkAPIService(config *configuration.Configuration, client Client, i Indexer) server.NetworkAPIServicer
- type AccountAPIService
- type BlockAPIService
- type Client
- type ConstructionAPIService
- func (s *ConstructionAPIService) ConstructionCombine(ctx context.Context, request *types.ConstructionCombineRequest) (*types.ConstructionCombineResponse, *types.Error)
- func (s *ConstructionAPIService) ConstructionDerive(ctx context.Context, request *types.ConstructionDeriveRequest) (*types.ConstructionDeriveResponse, *types.Error)
- func (s *ConstructionAPIService) ConstructionHash(ctx context.Context, request *types.ConstructionHashRequest) (*types.TransactionIdentifierResponse, *types.Error)
- func (s *ConstructionAPIService) ConstructionMetadata(ctx context.Context, request *types.ConstructionMetadataRequest) (*types.ConstructionMetadataResponse, *types.Error)
- func (s *ConstructionAPIService) ConstructionParse(ctx context.Context, request *types.ConstructionParseRequest) (*types.ConstructionParseResponse, *types.Error)
- func (s *ConstructionAPIService) ConstructionPayloads(ctx context.Context, request *types.ConstructionPayloadsRequest) (*types.ConstructionPayloadsResponse, *types.Error)
- func (s *ConstructionAPIService) ConstructionPreprocess(ctx context.Context, request *types.ConstructionPreprocessRequest) (*types.ConstructionPreprocessResponse, *types.Error)
- func (s *ConstructionAPIService) ConstructionSubmit(ctx context.Context, request *types.ConstructionSubmitRequest) (*types.TransactionIdentifierResponse, *types.Error)
- type Indexer
- type MempoolAPIService
- type NetworkAPIService
- func (s *NetworkAPIService) NetworkList(ctx context.Context, request *types.MetadataRequest) (*types.NetworkListResponse, *types.Error)
- func (s *NetworkAPIService) NetworkOptions(ctx context.Context, request *types.NetworkRequest) (*types.NetworkOptionsResponse, *types.Error)
- func (s *NetworkAPIService) NetworkStatus(ctx context.Context, request *types.NetworkRequest) (*types.NetworkStatusResponse, *types.Error)
- type ParseOperationMetadata
- type StatusRecorder
Constants ¶
const ( // NodeVersion is the version of // lbry core we are using. NodeVersion = "0.19.1.2" // HistoricalBalanceLookup indicates // that historical balance lookup is supported. HistoricalBalanceLookup = true // MempoolCoins indicates that // including mempool coins in the /account/coins // response is not supported. MempoolCoins = false // MiddlewareVersion is the version // of rosetta-lbry. We set this as a // variable instead of a constant because // we typically need the pointer of this // value. MiddlewareVersion = "0.0.8" )
Variables ¶
var ( // Errors contains all errors that could be returned // by this Rosetta implementation. Errors = []*types.Error{ ErrUnimplemented, ErrUnavailableOffline, ErrNotReady, ErrLbrycrdd, ErrBlockNotFound, ErrUnableToDerive, ErrUnclearIntent, ErrUnableToParseIntermediateResult, ErrScriptPubKeysMissing, ErrInvalidCoin, ErrUnableToDecodeAddress, ErrUnableToDecodeScriptPubKey, ErrUnableToCalculateSignatureHash, ErrUnsupportedScriptType, ErrUnableToComputePkScript, ErrUnableToGetCoins, ErrTransactionNotFound, ErrCouldNotGetFeeRate, ErrUnableToGetBalance, } // ErrUnimplemented is returned when an endpoint // is called that is not implemented. ErrUnimplemented = &types.Error{ Code: 0, Message: "Endpoint not implemented", } // is called that is not available offline. ErrUnavailableOffline = &types.Error{ Code: 1, Message: "Endpoint unavailable offline", } // ErrNotReady is returned when Lbrycrdd is not // yet ready to serve queries. ErrNotReady = &types.Error{ Code: 2, Message: "Lbrycrdd is not ready", Retriable: true, } // ErrLbrycrdd is returned when lbrycrdd // errors on a request. ErrLbrycrdd = &types.Error{ Code: 3, Message: "LBRYcrdd error", } // ErrBlockNotFound is returned when a block // is not available in the indexer. ErrBlockNotFound = &types.Error{ Code: 4, Message: "Block not found", } // ErrUnableToDerive is returned when an address // cannot be derived from a provided public key. ErrUnableToDerive = &types.Error{ Code: 5, Message: "Unable to derive address", } // ErrUnclearIntent is returned when operations // provided in /construction/preprocess or /construction/payloads // are not valid. ErrUnclearIntent = &types.Error{ Code: 6, Message: "Unable to parse intent", } // ErrUnableToParseIntermediateResult is returned // when a data structure passed between Construction // API calls is not valid. ErrUnableToParseIntermediateResult = &types.Error{ Code: 7, Message: "Unable to parse intermediate result", } // ErrScriptPubKeysMissing is returned when // the indexer cannot populate the required // lbry.ScriptPubKeys to construct a transaction. ErrScriptPubKeysMissing = &types.Error{ Code: 8, Message: "Missing ScriptPubKeys", } // ErrInvalidCoin is returned when a *types.Coin // cannot be parsed during construction. ErrInvalidCoin = &types.Error{ Code: 9, Message: "Coin is invalid", } // ErrUnableToDecodeAddress is returned when an address // cannot be parsed during construction. ErrUnableToDecodeAddress = &types.Error{ Code: 10, Message: "Unable to decode address", } // ErrUnableToDecodeScriptPubKey is returned when a // lbry.ScriptPubKey cannot be parsed during construction. ErrUnableToDecodeScriptPubKey = &types.Error{ Code: 11, Message: "Unable to decode ScriptPubKey", } // ErrUnableToCalculateSignatureHash is returned // when some payload to sign cannot be generated. ErrUnableToCalculateSignatureHash = &types.Error{ Code: 12, Message: "Unable to calculate signature hash", } // ErrUnsupportedScriptType is returned when // trying to sign an input with an unsupported // script type. ErrUnsupportedScriptType = &types.Error{ Code: 13, Message: "Script type is not supported", } // ErrUnableToComputePkScript is returned // when trying to compute the PkScript in // ConsructionParse. ErrUnableToComputePkScript = &types.Error{ Code: 14, Message: "Unable to compute PK script", } // ErrUnableToGetCoins is returned by the indexer // when it is not possible to get the coins // owned by a *types.AccountIdentifier. ErrUnableToGetCoins = &types.Error{ Code: 15, Message: "Unable to get coins", } // ErrTransactionNotFound is returned by the indexer // when it is not possible to find a transaction. ErrTransactionNotFound = &types.Error{ Code: 16, Message: "Transaction not found", } // ErrCouldNotGetFeeRate is returned when the fetch // to get the suggested fee rate fails. ErrCouldNotGetFeeRate = &types.Error{ Code: 17, Message: "Could not get suggested fee rate", } // ErrUnableToGetBalance is returned by the indexer // when it is not possible to get the balance // of a *types.AccountIdentifier. ErrUnableToGetBalance = &types.Error{ Code: 18, Message: "Unable to get balance", } )
Functions ¶
func LoggerMiddleware ¶
LoggerMiddleware is a simple logger middleware that prints the requests in an ad-hoc fashion to the stdlib's log.
func NewAccountAPIService ¶
func NewAccountAPIService( config *configuration.Configuration, i Indexer, ) server.AccountAPIServicer
NewAccountAPIService returns a new *AccountAPIService.
func NewBlockAPIService ¶
func NewBlockAPIService( config *configuration.Configuration, i Indexer, ) server.BlockAPIServicer
NewBlockAPIService creates a new instance of a BlockAPIService.
func NewBlockchainRouter ¶
func NewBlockchainRouter( config *configuration.Configuration, client Client, i Indexer, asserter *asserter.Asserter, ) http.Handler
NewBlockchainRouter creates a Mux http.Handler from a collection of server controllers.
func NewConstructionAPIService ¶
func NewConstructionAPIService( config *configuration.Configuration, client Client, i Indexer, ) server.ConstructionAPIServicer
NewConstructionAPIService creates a new instance of a ConstructionAPIService.
func NewMempoolAPIService ¶
func NewMempoolAPIService( config *configuration.Configuration, client Client, ) server.MempoolAPIServicer
NewMempoolAPIService creates a new instance of a MempoolAPIService.
func NewNetworkAPIService ¶
func NewNetworkAPIService( config *configuration.Configuration, client Client, i Indexer, ) server.NetworkAPIServicer
NewNetworkAPIService creates a new instance of a NetworkAPIService.
Types ¶
type AccountAPIService ¶
type AccountAPIService struct {
// contains filtered or unexported fields
}
AccountAPIService implements the server.AccountAPIServicer interface.
func (*AccountAPIService) AccountBalance ¶
func (s *AccountAPIService) AccountBalance( ctx context.Context, request *types.AccountBalanceRequest, ) (*types.AccountBalanceResponse, *types.Error)
AccountBalance implements /account/balance.
func (*AccountAPIService) AccountCoins ¶
func (s *AccountAPIService) AccountCoins( ctx context.Context, request *types.AccountCoinsRequest, ) (*types.AccountCoinsResponse, *types.Error)
AccountCoins implements /account/coins.
type BlockAPIService ¶
type BlockAPIService struct {
// contains filtered or unexported fields
}
BlockAPIService implements the server.BlockAPIServicer interface.
func (*BlockAPIService) Block ¶
func (s *BlockAPIService) Block( ctx context.Context, request *types.BlockRequest, ) (*types.BlockResponse, *types.Error)
Block implements the /block endpoint.
func (*BlockAPIService) BlockTransaction ¶
func (s *BlockAPIService) BlockTransaction( ctx context.Context, request *types.BlockTransactionRequest, ) (*types.BlockTransactionResponse, *types.Error)
BlockTransaction implements the /block/transaction endpoint.
type Client ¶
type Client interface { GetPeers(context.Context) ([]*types.Peer, error) SendRawTransaction(context.Context, string) (string, error) SuggestedFeeRate(context.Context, int64) (float64, error) RawMempool(context.Context) ([]string, error) }
Client is used by the servicers to get Peer information and to submit transactions.
type ConstructionAPIService ¶
type ConstructionAPIService struct {
// contains filtered or unexported fields
}
ConstructionAPIService implements the server.ConstructionAPIServicer interface.
func (*ConstructionAPIService) ConstructionCombine ¶
func (s *ConstructionAPIService) ConstructionCombine( ctx context.Context, request *types.ConstructionCombineRequest, ) (*types.ConstructionCombineResponse, *types.Error)
ConstructionCombine implements the /construction/combine endpoint.
func (*ConstructionAPIService) ConstructionDerive ¶
func (s *ConstructionAPIService) ConstructionDerive( ctx context.Context, request *types.ConstructionDeriveRequest, ) (*types.ConstructionDeriveResponse, *types.Error)
ConstructionDerive implements the /construction/derive endpoint.
func (*ConstructionAPIService) ConstructionHash ¶
func (s *ConstructionAPIService) ConstructionHash( ctx context.Context, request *types.ConstructionHashRequest, ) (*types.TransactionIdentifierResponse, *types.Error)
ConstructionHash implements the /construction/hash endpoint.
func (*ConstructionAPIService) ConstructionMetadata ¶
func (s *ConstructionAPIService) ConstructionMetadata( ctx context.Context, request *types.ConstructionMetadataRequest, ) (*types.ConstructionMetadataResponse, *types.Error)
ConstructionMetadata implements the /construction/metadata endpoint.
func (*ConstructionAPIService) ConstructionParse ¶
func (s *ConstructionAPIService) ConstructionParse( ctx context.Context, request *types.ConstructionParseRequest, ) (*types.ConstructionParseResponse, *types.Error)
ConstructionParse implements the /construction/parse endpoint.
func (*ConstructionAPIService) ConstructionPayloads ¶
func (s *ConstructionAPIService) ConstructionPayloads( ctx context.Context, request *types.ConstructionPayloadsRequest, ) (*types.ConstructionPayloadsResponse, *types.Error)
ConstructionPayloads implements the /construction/payloads endpoint.
func (*ConstructionAPIService) ConstructionPreprocess ¶
func (s *ConstructionAPIService) ConstructionPreprocess( ctx context.Context, request *types.ConstructionPreprocessRequest, ) (*types.ConstructionPreprocessResponse, *types.Error)
ConstructionPreprocess implements the /construction/preprocess endpoint.
func (*ConstructionAPIService) ConstructionSubmit ¶
func (s *ConstructionAPIService) ConstructionSubmit( ctx context.Context, request *types.ConstructionSubmitRequest, ) (*types.TransactionIdentifierResponse, *types.Error)
ConstructionSubmit implements the /construction/submit endpoint.
type Indexer ¶
type Indexer interface { GetBlockLazy( context.Context, *types.PartialBlockIdentifier, ) (*types.BlockResponse, error) GetBlockTransaction( context.Context, *types.BlockIdentifier, *types.TransactionIdentifier, ) (*types.Transaction, error) GetCoins( context.Context, *types.AccountIdentifier, ) ([]*types.Coin, *types.BlockIdentifier, error) GetScriptPubKeys( context.Context, []*types.Coin, ) ([]*lbry.ScriptPubKey, error) GetBalance( context.Context, *types.AccountIdentifier, *types.Currency, *types.PartialBlockIdentifier, ) (*types.Amount, *types.BlockIdentifier, error) }
Indexer is used by the servicers to get block and account data.
type MempoolAPIService ¶
type MempoolAPIService struct {
// contains filtered or unexported fields
}
MempoolAPIService implements the server.MempoolAPIServicer interface.
func (*MempoolAPIService) Mempool ¶
func (s *MempoolAPIService) Mempool( ctx context.Context, request *types.NetworkRequest, ) (*types.MempoolResponse, *types.Error)
Mempool implements the /mempool endpoint.
func (*MempoolAPIService) MempoolTransaction ¶
func (s *MempoolAPIService) MempoolTransaction( ctx context.Context, request *types.MempoolTransactionRequest, ) (*types.MempoolTransactionResponse, *types.Error)
MempoolTransaction implements the /mempool/transaction endpoint.
type NetworkAPIService ¶
type NetworkAPIService struct {
// contains filtered or unexported fields
}
NetworkAPIService implements the server.NetworkAPIServicer interface.
func (*NetworkAPIService) NetworkList ¶
func (s *NetworkAPIService) NetworkList( ctx context.Context, request *types.MetadataRequest, ) (*types.NetworkListResponse, *types.Error)
NetworkList implements the /network/list endpoint
func (*NetworkAPIService) NetworkOptions ¶
func (s *NetworkAPIService) NetworkOptions( ctx context.Context, request *types.NetworkRequest, ) (*types.NetworkOptionsResponse, *types.Error)
NetworkOptions implements the /network/options endpoint.
func (*NetworkAPIService) NetworkStatus ¶
func (s *NetworkAPIService) NetworkStatus( ctx context.Context, request *types.NetworkRequest, ) (*types.NetworkStatusResponse, *types.Error)
NetworkStatus implements the /network/status endpoint.
type ParseOperationMetadata ¶
type ParseOperationMetadata struct {
ScriptPubKey *lbry.ScriptPubKey `json:"scriptPubKey"`
}
ParseOperationMetadata is returned from ConstructionParse.
type StatusRecorder ¶
type StatusRecorder struct { http.ResponseWriter Code int }
StatusRecorder is used to surface the status code of a HTTP response. We must use this wrapping because the status code is not exposed by the http.ResponseWriter in the http.HandlerFunc.
Inspired by: https://stackoverflow.com/questions/53272536/how-do-i-get-response-statuscode-in-golang-middleware
func NewStatusRecorder ¶
func NewStatusRecorder(w http.ResponseWriter) *StatusRecorder
NewStatusRecorder returns a new *StatusRecorder.
func (*StatusRecorder) WriteHeader ¶
func (r *StatusRecorder) WriteHeader(code int)
WriteHeader stores the status code of a response.