{"modulePath":"github.com/chainbing/node","version":"v0.0.0-20220110094656-e04c47b4d7c8","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package api\n\nPackage api implements the public interface of the node using a HTTP REST API. There are two subsets of endpoints: - coordinatorEndpoints: used to receive L2 transactions and account creation authorizations. Targeted for wallets. - explorerEndpoints: used to provide all sorts of information about the network. Targeted for explorers and similar services.\n\nAbout the configuration of the API: - The API is supposed to be launched using the cli found at the package cli/node, and configured through the configuration file. - The mentioned configuration file allows exposing any combination of the endpoint subsets. - Although the API can run in a \"standalone\" manner using the serveapi command, it won't work properly unless another process acting as a coord or sync is filling the HistoryDB.\n\nDesign principles and considerations: - In order to decouple the API process from the rest of the node, all the communication between this package and the rest of the system is done through the SQL database. As a matter of fact, the only public function of the package is the constructor NewAPI. All the information needed for the API to work should be obtained through the configuration file of the cli or the database. - The format of the requests / responses doesn't match directly with the common types, and for this reason, the package api/apitypes is used to facilitate the format conversion. Most of the time, this is done directly at the db level. - The API endpoints are fully documented using OpenAPI aka Swagger. All the endpoints are tested against the spec to ensure consistency between implementation and specification. To get a sense of which endpoints exist and how they work, it's strongly recommended to check this specification. The specification can be found at api/swagger.yml. - In general, all the API endpoints produce queries to the SQL database in order to retrieve / insert the requested information. The most notable exceptions to this are the /config endpoint, which returns a static object generated at construction time, and the /state, which also is retrieved from the database, but it's generated by API/stateapiupdater package.\n\n## Constants\n\n```go\nconst (\n\n\t// ErrParamValidationFailedCode code for param validation failed error\n\tErrParamValidationFailedCode apiErrorCode = 1\n\t// ErrParamValidationFailedType type for param validation failed error\n\tErrParamValidationFailedType apiErrorType = \"ErrParamValidationFailed\"\n\n\t// ErrDuplicatedKey error message returned when trying to insert an item with duplicated key\n\tErrDuplicatedKey = \"Item already exists\"\n\t// ErrDuplicatedKeyCode code for duplicated key error\n\tErrDuplicatedKeyCode apiErrorCode = 2\n\t// ErrDuplicatedKeyType type for duplicated key error\n\tErrDuplicatedKeyType apiErrorType = \"ErrDuplicatedKey\"\n\n\t// ErrSQLTimeout error message returned when timeout due to SQL connection\n\tErrSQLTimeout = \"The node is under heavy pressure, please try again later\"\n\t// ErrSQLTimeoutCode code for sql timeout error\n\tErrSQLTimeoutCode apiErrorCode = 3\n\t// ErrSQLTimeoutType type for sql timeout type\n\tErrSQLTimeoutType apiErrorType = \"ErrSQLTimeout\"\n\n\t// ErrSQLNoRows error message returned when there is no such records\n\tErrSQLNoRows = \"record(s) were not found for this query and/or the parameters entered\"\n\t// ErrSQLNoRowsCode code for no rows error\n\tErrSQLNoRowsCode apiErrorCode = 4\n\t// ErrSQLNoRowsType type for now rows error\n\tErrSQLNoRowsType apiErrorType = \"ErrSQLNoRows\"\n\n\t// ErrExitAmount0 error message returned when receiving (and rejecting) a tx of type exit with amount 0\n\tErrExitAmount0 = \"Transaction rejected because an exit with amount 0 has no sense\"\n\t// ErrExitAmount0Code code for 0 exit amount error\n\tErrExitAmount0Code apiErrorCode = 5\n\t// ErrExitAmount0Type type for 0 exit amount error\n\tErrExitAmount0Type apiErrorType = \"ErrExitAmount0\"\n\n\t// ErrInvalidTxTypeOrTxIDCode code for invalid tx type or txID error\n\tErrInvalidTxTypeOrTxIDCode apiErrorCode = 6\n\t// ErrInvalidTxTypeOrTxIDType type for invalid tx type or txID error\n\tErrInvalidTxTypeOrTxIDType apiErrorType = \"ErrInvalidTxTypeOrTxID\"\n\n\t// ErrFeeOverflowCode code for fee overflow code error\n\tErrFeeOverflowCode apiErrorCode = 7\n\t// ErrFeeOverflowType type for fee overflow code type\n\tErrFeeOverflowType apiErrorType = \"ErrFeeOverflow\"\n\n\t// ErrGettingSenderAccountCode code for getting sender account error\n\tErrGettingSenderAccountCode apiErrorCode = 8\n\t// ErrGettingSenderAccountType type for getting sender account error\n\tErrGettingSenderAccountType apiErrorType = \"ErrGettingSenderAccount\"\n\n\t// ErrAccountTokenNotEqualTxTokenCode code for account token not equal tx token error\n\tErrAccountTokenNotEqualTxTokenCode apiErrorCode = 9\n\t// ErrAccountTokenNotEqualTxTokenType type for account token not equal tx token type\n\tErrAccountTokenNotEqualTxTokenType apiErrorType = \"ErrAccountTokenNotEqualTxToken\"\n\n\t// ErrInvalidNonceCode code for invalid nonce error\n\tErrInvalidNonceCode apiErrorCode = 10\n\t// ErrInvalidNonceType type for invalid nonce error\n\tErrInvalidNonceType apiErrorType = \"ErrInvalidNonce\"\n\n\t// ErrInvalidSignatureCode code for invalid signature error\n\tErrInvalidSignatureCode apiErrorCode = 11\n\t// ErrInvalidSignatureType type for invalid signature error\n\tErrInvalidSignatureType apiErrorType = \"ErrInvalidSignature\"\n\n\t// ErrGettingReceiverAccountCode code for getting receiver account error\n\tErrGettingReceiverAccountCode apiErrorCode = 12\n\t// ErrGettingReceiverAccountType type for getting receiver account error\n\tErrGettingReceiverAccountType apiErrorType = \"ErrGettingReceiverAccount\"\n\n\t// ErrCantSendToEthAddrCode code when can't send to eth addr code error appeared\n\tErrCantSendToEthAddrCode apiErrorCode = 13\n\t// ErrCantSendToEthAddrType type when can't send to eth addr code error appeared\n\tErrCantSendToEthAddrType apiErrorType = \"ErrCantSendToEthAddr\"\n\n\t// ErrNotAtomicTxsInPostPoolTx error message returned when received an non-atomic transaction inside atomic pool\n\tErrNotAtomicTxsInPostPoolTx = \"atomic transactions are only accepted in POST /atomic-pool\"\n\t// ErrNotAtomicTxsInPostPoolTxCode code filter atomic transactions on POST /transactions-pool\n\tErrNotAtomicTxsInPostPoolTxCode apiErrorCode = 14\n\t// ErrNotAtomicTxsInPostPoolTxType type filter atomic transactions on POST /transactions-pool\n\tErrNotAtomicTxsInPostPoolTxType apiErrorType = \"ErrNotAtomicTxsInPostPoolTx\"\n\n\t// ErrFailedToGetCurrentBlockCode code when can't get current block in /slots request\n\tErrFailedToGetCurrentBlockCode apiErrorCode = 15\n\t// ErrFailedToGetCurrentBlockType type when can't get current block in /slots request\n\tErrFailedToGetCurrentBlockType apiErrorType = \"ErrFailedToGetCurrentBlock\"\n\n\t// ErrFailedToGetAuctionVarsCode code when can't get auction vars in /slots request\n\tErrFailedToGetAuctionVarsCode apiErrorCode = 16\n\t// ErrFailedToGetAuctionVarsType type when can't get auction vars in /slots request\n\tErrFailedToGetAuctionVarsType apiErrorType = \"ErrFailedToGetAuctionVars\"\n\n\t// ErrFailedToAddEmptySlotCode code when can't add empty slot in /slots request\n\tErrFailedToAddEmptySlotCode apiErrorCode = 17\n\t// ErrFailedToAddEmptySlotType type when can't add empty slot in /slots request\n\tErrFailedToAddEmptySlotType apiErrorType = \"ErrFailedToAddEmptySlot\"\n\n\t// ErrTxsNotAtomic error message returned when receiving (and rejecting) txs in the atomic endpoint with not all txs being atomic\n\tErrTxsNotAtomic = \"there is at least one transaction in the payload that could be forged without the others\"\n\t// ErrTxsNotAtomicCode error code\n\tErrTxsNotAtomicCode apiErrorCode = 18\n\t// ErrTxsNotAtomicType error type\n\tErrTxsNotAtomicType apiErrorType = \"ErrTxsNotAtomic\"\n\n\t// ErrSingleTxInAtomicEndpoint only one tx sent to the atomic-pool endpoint\n\tErrSingleTxInAtomicEndpoint = \"to use the atomic-pool endpoint at least two transactions are required\"\n\t// ErrSingleTxInAtomicEndpointCode error code\n\tErrSingleTxInAtomicEndpointCode apiErrorCode = 19\n\t// ErrSingleTxInAtomicEndpointType error type\n\tErrSingleTxInAtomicEndpointType apiErrorType = \"ErrSingleTxInAtomicEndpoint\"\n\n\t// ErrInvalidRqOffset error message returned when received an invalid request offset\n\tErrInvalidRqOffset = \"invalid requestOffset. Valid values goes from 0 to 7\"\n\n\t// ErrRqOffsetOutOfBounds error message returned when transaction tries to access another out the bounds of the array\n\tErrRqOffsetOutOfBounds = \"one of the transactions requested another one outside the bounds of the provided array\"\n\t// ErrRqOffsetOutOfBoundsCode error code\n\tErrRqOffsetOutOfBoundsCode = 20\n\t// ErrRqOffsetOutOfBoundsType error type\n\tErrRqOffsetOutOfBoundsType = \"ErrRqOffsetOutOfBounds\"\n\n\t// ErrInvalidAtomicGroupID error message returned when received an invalid AtomicGroupID\n\tErrInvalidAtomicGroupID = \"invalid atomicGroupId\"\n\t// ErrInvalidAtomicGroupIDCode error code\n\tErrInvalidAtomicGroupIDCode = 21\n\t// ErrInvalidAtomicGroupIDType error type\n\tErrInvalidAtomicGroupIDType = \"ErrInvalidAtomicGroupID\"\n\n\t// ErrFailedToFindOffsetToRelativePositionCode error code when can't find offset to relative position\n\tErrFailedToFindOffsetToRelativePositionCode = 22\n\t// ErrFailedToFindOffsetToRelativePositionType error type\n\tErrFailedToFindOffsetToRelativePositionType = \"ErrFailedToFindOffsetToRelativePosition\"\n\n\t// ErrFeeTooLowCode code for fee too low error\n\tErrFeeTooLowCode apiErrorCode = 23\n\t// ErrFeeTooLowType type for fee too low error\n\tErrFeeTooLowType apiErrorType = \"ErrFeeTooLow\"\n\n\t// ErrFeeTooBigCode code for fee too big error\n\tErrFeeTooBigCode apiErrorCode = 24\n\t// ErrFeeTooBigType type for fee too big error\n\tErrFeeTooBigType apiErrorType = \"ErrFeeTooBig\"\n\n\t// ErrNothingToUpdateCode code for nothing to update error\n\tErrNothingToUpdateCode apiErrorCode = 25\n\t// ErrNothingToUpdateType type for nothing to update type\n\tErrNothingToUpdateType apiErrorType = \"ErrNothingToUpdate\"\n\n\t// ErrUnsupportedMaxNumBatch error message returned when tx.MaxNumBatch != 0 until the feature is fully implemented\n\tErrUnsupportedMaxNumBatch = \"currently only supported value for maxNumBatch is 0, this will change soon when the feature is fully implemented\"\n)\n```\n\n## Functions\n\n```go\nfunc RequestOffset2RelativePosition(rqoffset uint8) (int, error)\n```\nRequestOffset2RelativePosition translates from 0 to 7 to protocol position\n\n## Types\n\n```go\ntype API struct {\n\t// contains filtered or unexported fields\n}\n```\nAPI serves HTTP requests to allow external interaction with the Chainbing node\n\n```go\nfunc NewAPI(\n\tversion string,\n\tcoordinatorEndpoints, explorerEndpoints bool,\n\tserver *gin.Engine,\n\thdb *historydb.HistoryDB,\n\tl2db *l2db.L2DB,\n\tstateDB *statedb.StateDB,\n\tethClient *ethclient.Client,\n\tforgerAddress *ethCommon.Address,\n) (*API, error)\n```\nNewAPI sets the endpoints and the appropriate handlers, but doesn't start the server\n\n```go\ntype Config struct {\n\tRollupConstants   common.RollupConstants\n\tAuctionConstants  common.AuctionConstants\n\tWDelayerConstants common.WDelayerConstants\n\tChainID           uint16\n\tChainbingAddress  ethCommon.Address\n}\n```\nConfig of the API\n\n","path":"github.com/chainbing/node/api","name":"api","synopsis":"Package api implements the public interface of the node using a HTTP REST API.","isRedistributable":true}
