Documentation ¶
Index ¶
- Constants
- func HttpGET(url string) (resp *http.Response, err error)
- func HttpGETAuthenticated(url string, password string) (resp *http.Response, err error)
- func HttpPOST(url string, data string) (resp *http.Response, err error)
- func HttpPOSTAuthenticated(url string, data string, password string) (resp *http.Response, err error)
- func RequirePassword(h httprouter.Handle, password string) httprouter.Handle
- func RequireUserAgent(h http.Handler, ua string) http.Handler
- func UnrecognizedCallHandler(w http.ResponseWriter, req *http.Request)
- func WriteError(w http.ResponseWriter, err Error, code int)
- func WriteJSON(w http.ResponseWriter, obj interface{})
- func WriteSuccess(w http.ResponseWriter)
- type API
- type Client
- type ConsensusGET
- type ConsensusGetTransaction
- type ConsensusGetUnspentBlockstakeOutput
- type ConsensusGetUnspentCoinOutput
- type Error
- type ExplorerBlock
- type ExplorerBlockGET
- type ExplorerBlockStakeOutput
- type ExplorerCoinOutput
- type ExplorerGET
- type ExplorerHashGET
- type ExplorerTransaction
- type GatewayGET
- type TransactionPoolGET
- type TransactionPoolPOST
- type UnspentBlockstakeOutput
- type UnspentCoinOutput
- type WalletAddressGET
- type WalletAddressesGET
- type WalletBlockStakeStatsGET
- type WalletBlockStakesPOST
- type WalletBlockStakesPOSTResp
- type WalletCoinsPOST
- type WalletCoinsPOSTResp
- type WalletCreateTransactionPOST
- type WalletCreateTransactionRESP
- type WalletGET
- type WalletInitPOST
- type WalletKeyGet
- type WalletListLockedGET
- type WalletListUnlockedGET
- type WalletSeedsGET
- type WalletTransactionGETid
- type WalletTransactionPOST
- type WalletTransactionPOSTResponse
- type WalletTransactionsGET
- type WalletTransactionsGETaddr
Constants ¶
const ( HashTypeTransactionIDStr = "transactionid" HashTypeCoinOutputIDStr = "coinoutputid" HashTypeBlockStakeOutputIDStr = "blockstakeoutputid" )
hash type string constants
Variables ¶
This section is empty.
Functions ¶
func HttpGET ¶
HttpGET is a utility function for making http get requests to sia with a whitelisted user-agent. A non-2xx response does not return an error.
func HttpGETAuthenticated ¶
HttpGETAuthenticated is a utility function for making authenticated http get requests to sia with a whitelisted user-agent and the supplied password. A non-2xx response does not return an error.
func HttpPOST ¶
HttpPOST is a utility function for making post requests to sia with a whitelisted user-agent. A non-2xx response does not return an error.
func HttpPOSTAuthenticated ¶
func HttpPOSTAuthenticated(url string, data string, password string) (resp *http.Response, err error)
HttpPOSTAuthenticated is a utility function for making authenticated http post requests to sia with a whitelisted user-agent and the supplied password. A non-2xx response does not return an error.
func RequirePassword ¶
func RequirePassword(h httprouter.Handle, password string) httprouter.Handle
RequirePassword is middleware that requires a request to authenticate with a password using HTTP basic auth. Usernames are ignored. Empty passwords indicate no authentication is required.
func RequireUserAgent ¶
RequireUserAgent is middleware that requires all requests to set a UserAgent that contains the specified string.
func UnrecognizedCallHandler ¶
func UnrecognizedCallHandler(w http.ResponseWriter, req *http.Request)
UnrecognizedCallHandler handles calls to unknown pages (404).
func WriteError ¶
func WriteError(w http.ResponseWriter, err Error, code int)
WriteError an error to the API caller.
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, obj interface{})
WriteJSON writes the object to the ResponseWriter. If the encoding fails, an error is written instead. The Content-Type of the response header is set accordingly.
func WriteSuccess ¶
func WriteSuccess(w http.ResponseWriter)
WriteSuccess writes the HTTP header with status 204 No Content to the ResponseWriter. WriteSuccess should only be used to indicate that the requested action succeeded AND there is no data to return.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API encapsulates a collection of modules and implements a http.Handler to access their methods.
func New ¶
func New(requiredUserAgent string, requiredPassword string, cs modules.ConsensusSet, e modules.Explorer, g modules.Gateway, tp modules.TransactionPool, w modules.Wallet) *API
New creates a new Sia API from the provided modules. The API will require authentication using HTTP basic auth for certain endpoints of the supplied password is not the empty string. Usernames are ignored for authentication.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client holds fields to make requests to a Sia API.
func NewClient ¶
NewClient creates a new api.Client using the provided address and password. If password is not the empty string, HTTP basic authentication will be used to communicate with the API.
type ConsensusGET ¶
type ConsensusGET struct { Synced bool `json:"synced"` Height types.BlockHeight `json:"height"` CurrentBlock types.BlockID `json:"currentblock"` Target types.Target `json:"target"` }
ConsensusGET contains general information about the consensus set, with tags to support idiomatic json encodings.
type ConsensusGetTransaction ¶ added in v0.6.0
type ConsensusGetTransaction struct { types.Transaction TxShortID types.TransactionShortID `json:"shortid,omitempty"` }
ConsensusGetTransaction is the object returned by a GET request to /consensus/transaction/:id
type ConsensusGetUnspentBlockstakeOutput ¶ added in v1.0.6
type ConsensusGetUnspentBlockstakeOutput struct {
Output types.BlockStakeOutput `json:"output"`
}
ConsensusGetUnspentBlockstakeOutput is the object returned by a GET request to /consensus/unspent/blockstakeoutput/:id
type ConsensusGetUnspentCoinOutput ¶ added in v1.0.6
type ConsensusGetUnspentCoinOutput struct {
Output types.CoinOutput `json:"output"`
}
ConsensusGetUnspentCoinOutput is the object returned by a GET request to /consensus/unspent/coinoutput/:id
type Error ¶
type Error struct { // Message describes the error in English. Typically it is set to // `err.Error()`. This field is required. Message string `json:"message"` }
Error is a type that is encoded as JSON and returned in an API response in the event of an error. Only the Message field is required. More fields may be added to this struct in the future for better error reporting.
type ExplorerBlock ¶
type ExplorerBlock struct { MinerPayoutIDs []types.CoinOutputID `json:"minerpayoutids"` Transactions []ExplorerTransaction `json:"transactions"` RawBlock types.Block `json:"rawblock"` HexBlock string `json:"hexblock"` modules.BlockFacts }
ExplorerBlock is a block with some extra information such as the id and height. This information is provided for programs that may not be complex enough to compute the ID on their own.
type ExplorerBlockGET ¶
type ExplorerBlockGET struct {
Block ExplorerBlock `json:"block"`
}
ExplorerBlockGET is the object returned by a GET request to /explorer/block.
type ExplorerBlockStakeOutput ¶ added in v1.0.7
type ExplorerBlockStakeOutput struct { types.BlockStakeOutput UnlockHash types.UnlockHash `json:"unlockhash"` }
ExplorerBlockStakeOutput is the same a regular types.BlockStakeOutput, but with the addition of the pre-computed UnlockHash of its condition.
type ExplorerCoinOutput ¶ added in v1.0.7
type ExplorerCoinOutput struct { types.CoinOutput UnlockHash types.UnlockHash `json:"unlockhash"` }
ExplorerCoinOutput is the same a regular types.CoinOutput, but with the addition of the pre-computed UnlockHash of its condition.
type ExplorerGET ¶
type ExplorerGET struct {
modules.BlockFacts
}
ExplorerGET is the object returned as a response to a GET request to /explorer.
type ExplorerHashGET ¶
type ExplorerHashGET struct { HashType string `json:"hashtype"` Block ExplorerBlock `json:"block"` Blocks []ExplorerBlock `json:"blocks"` Transaction ExplorerTransaction `json:"transaction"` Transactions []ExplorerTransaction `json:"transactions"` Unconfirmed bool `json:"unconfirmed"` }
ExplorerHashGET is the object returned as a response to a GET request to /explorer/hash. The HashType will indicate whether the hash corresponds to a block id, a transaction id, a siacoin output id, a file contract id, or a siafund output id. In the case of a block id, 'Block' will be filled out and all the rest of the fields will be blank. In the case of a transaction id, 'Transaction' will be filled out and all the rest of the fields will be blank. For everything else, 'Transactions' and 'Blocks' will/may be filled out and everything else will be blank.
type ExplorerTransaction ¶
type ExplorerTransaction struct { ID types.TransactionID `json:"id"` Height types.BlockHeight `json:"height"` Parent types.BlockID `json:"parent"` RawTransaction types.Transaction `json:"rawtransaction"` HexTransaction string `json:"hextransaction"` CoinInputOutputs []ExplorerCoinOutput `json:"coininputoutputs"` // the outputs being spent CoinOutputIDs []types.CoinOutputID `json:"coinoutputids"` CoinOutputUnlockHashes []types.UnlockHash `json:"coinoutputunlockhashes"` BlockStakeInputOutputs []ExplorerBlockStakeOutput `json:"blockstakeinputoutputs"` // the outputs being spent BlockStakeOutputIDs []types.BlockStakeOutputID `json:"blockstakeoutputids"` BlockStakeOutputUnlockHashes []types.UnlockHash `json:"blockstakeunlockhashes"` }
ExplorerTransaction is a transcation with some extra information such as the parent block. This information is provided for programs that may not be complex enough to compute the extra information on their own.
type GatewayGET ¶
type GatewayGET struct { NetAddress modules.NetAddress `json:"netaddress"` Peers []modules.Peer `json:"peers"` }
GatewayGET contains the fields returned by a GET call to "/gateway".
type TransactionPoolGET ¶
type TransactionPoolGET struct {
Transactions []types.Transaction `json:"transactions"`
}
type TransactionPoolPOST ¶ added in v0.6.0
type TransactionPoolPOST struct {
TransactionID types.TransactionID `json:"transactionid"`
}
TransactionPoolPOST is the success response for a POST to /transactionpool/transactions. It is the ID of the newly posted transaction
type UnspentBlockstakeOutput ¶ added in v1.0.6
type UnspentBlockstakeOutput struct { ID types.BlockStakeOutputID `json:"id"` Output types.BlockStakeOutput `json:"output"` }
UnspentBlockstakeOutput is a blockstake output and its associated ID
type UnspentCoinOutput ¶ added in v1.0.6
type UnspentCoinOutput struct { ID types.CoinOutputID `json:"id"` Output types.CoinOutput `json:"coinoutput"` }
UnspentCoinOutput is a coin output and its associated ID
type WalletAddressGET ¶
type WalletAddressGET struct {
Address types.UnlockHash `json:"address"`
}
WalletAddressGET contains an address returned by a GET call to /wallet/address.
type WalletAddressesGET ¶
type WalletAddressesGET struct {
Addresses []types.UnlockHash `json:"addresses"`
}
WalletAddressesGET contains the list of wallet addresses returned by a GET call to /wallet/addresses.
type WalletBlockStakeStatsGET ¶ added in v0.1.0
type WalletBlockStakeStatsGET struct { TotalActiveBlockStake types.Currency `json:"totalactiveblockstake"` TotalBlockStake types.Currency `json:"totalblockstake"` TotalFeeLast1000 types.Currency `json:"totalfeelast1000"` TotalBCLast1000 uint64 `json:"totalbclast1000"` BlockCount uint64 `json:"blockcount"` TotalBCLast1000t uint64 `json:"totalbclast1000t"` BlockStakeState []uint64 `json:"blockstakestate"` BlockStakeNumOf []types.Currency `json:"blockstakenumof"` BlockStakeUTXOAddress []types.BlockStakeOutputID `json:"blockstakeutxoaddress"` }
WalletBlockStakeStatsGET contains blockstake statistical info of the wallet.
type WalletBlockStakesPOST ¶
type WalletBlockStakesPOST struct {
BlockStakeOutputs []types.BlockStakeOutput `json:"blockstakeoutputs`
}
WalletBlockStakesPOST is given by the user to indicate to where to send how much blockstakes
type WalletBlockStakesPOSTResp ¶ added in v1.0.2
type WalletBlockStakesPOSTResp struct {
TransactionID types.TransactionID `json:"transactionids"`
}
WalletBlockStakesPOSTResp Resp contains the ID of the transaction that was created as a result of a POST call to /wallet/blockstakes.
type WalletCoinsPOST ¶ added in v0.1.0
type WalletCoinsPOST struct {
CoinOutputs []types.CoinOutput `json:"coinoutputs`
}
WalletCoinsPOST is given by the user to indicate to where to send how much coins
type WalletCoinsPOSTResp ¶ added in v1.0.2
type WalletCoinsPOSTResp struct {
TransactionID types.TransactionID `json:"transactionid"`
}
WalletCoinsPOSTResp Resp contains the ID of the transaction that was created as a result of a POST call to /wallet/coins.
type WalletCreateTransactionPOST ¶ added in v1.0.6
type WalletCreateTransactionPOST struct { CoinInputs []types.CoinOutputID `json:"coininputs"` BlockStakeInputs []types.BlockStakeOutputID `json:"blockstakeinputs"` CoinOutputs []types.CoinOutput `json:"coinoutputs"` BlockStakeOutputs []types.BlockStakeOutput `json:"blockstakeoutputs"` }
WalletCreateTransactionPOST is a list of coin and blockstake inputs and outputs The values in the coin and blockstake input and outputs pair must match exactly (also accounting for miner fees)
type WalletCreateTransactionRESP ¶ added in v1.0.6
type WalletCreateTransactionRESP struct {
Transaction types.Transaction `json:"transaction"`
}
WalletCreateTransactionRESP wraps the transaction returned by the walletcreatetransaction endpoint
type WalletGET ¶
type WalletGET struct { Encrypted bool `json:"encrypted"` Unlocked bool `json:"unlocked"` ConfirmedCoinBalance types.Currency `json:"confirmedcoinbalance"` ConfirmedLockedCoinBalance types.Currency `json:"confirmedlockedcoinbalance"` UnconfirmedOutgoingCoins types.Currency `json:"unconfirmedoutgoingcoins"` UnconfirmedIncomingCoins types.Currency `json:"unconfirmedincomingcoins"` BlockStakeBalance types.Currency `json:"blockstakebalance"` LockedBlockStakeBalance types.Currency `json:"lockedblockstakebalance"` MultiSigWallets []modules.MultiSigWallet `json:"multisigwallets"` }
WalletGET contains general information about the wallet.
type WalletInitPOST ¶
type WalletInitPOST struct {
PrimarySeed string `json:"primaryseed"`
}
WalletInitPOST contains the mnemonic of the primary seed, the seed which is either given by you as part of the request, or generated for you if none is given. If it's the first case, the returned primary seed mnemonic should be the same as the one you already know. POST call to /wallet/init.
type WalletKeyGet ¶ added in v0.6.0
type WalletKeyGet struct { AlgorithmSpecifier types.Specifier `json:"specifier"` PublicKey types.ByteSlice `json:"publickey"` SecretKey types.ByteSlice `json:"secretkey"` }
WalletKeyGet contains the public and private key used by the wallet.
type WalletListLockedGET ¶ added in v1.0.6
type WalletListLockedGET struct { LockedCoinOutputs []UnspentCoinOutput `json:"lockedcoinoutputs"` LockedBlockstakeOutputs []UnspentBlockstakeOutput `json:"lockedblockstakeoutputs"` }
WalletListLockedGET contains the set of unspent, locked coin and blockstake outputs owned by the wallet
type WalletListUnlockedGET ¶ added in v1.0.6
type WalletListUnlockedGET struct { UnlockedCoinOutputs []UnspentCoinOutput `json:"unlockedcoinoutputs"` UnlockedBlockstakeOutputs []UnspentBlockstakeOutput `json:"unlockedblockstakeoutputs"` }
WalletListUnlockedGET contains the set of unspent, unlocked coin and blockstake outputs owned by the wallet.
type WalletSeedsGET ¶
type WalletSeedsGET struct { PrimarySeed string `json:"primaryseed"` AddressesRemaining int `json:"addressesremaining"` AllSeeds []string `json:"allseeds"` }
WalletSeedsGET contains the seeds used by the wallet.
type WalletTransactionGETid ¶
type WalletTransactionGETid struct {
Transaction modules.ProcessedTransaction `json:"transaction"`
}
WalletTransactionGETid contains the transaction returned by a call to /wallet/transaction/$(id)
type WalletTransactionPOST ¶ added in v0.6.0
type WalletTransactionPOST struct { Condition types.UnlockConditionProxy `json:"condition"` Amount types.Currency `json:"amount"` Data string `json:"data,omitempty"` }
WalletTransactionPOST contains the unlockhash and amount of money to send, during a POST call to /wallet/transaction, funding the output, using available inputs in the wallet.
type WalletTransactionPOSTResponse ¶ added in v0.6.0
type WalletTransactionPOSTResponse struct {
Transaction types.Transaction `json:"transaction"`
}
WalletTransactionPOSTResponse contains the ID of the transaction that was created as a result of a POST call to /wallet/transaction.
type WalletTransactionsGET ¶
type WalletTransactionsGET struct { ConfirmedTransactions []modules.ProcessedTransaction `json:"confirmedtransactions"` UnconfirmedTransactions []modules.ProcessedTransaction `json:"unconfirmedtransactions"` }
WalletTransactionsGET contains the specified set of confirmed and unconfirmed transactions.
type WalletTransactionsGETaddr ¶
type WalletTransactionsGETaddr struct { ConfirmedTransactions []modules.ProcessedTransaction `json:"confirmedtransactions"` UnconfirmedTransactions []modules.ProcessedTransaction `json:"unconfirmedtransactions"` }
WalletTransactionsGETaddr contains the set of wallet transactions relevant to the input address provided in the call to /wallet/transaction/$(addr)