restful

package
v0.0.0-...-3b19a5f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2020 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package error privides error code for rest

* Copyright (C) 2020 The poly network Authors * This file is part of The poly network library. * * The poly network is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The poly network is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with The poly network . If not, see <http://www.gnu.org/licenses/>.

* Copyright (C) 2020 The poly network Authors * This file is part of The poly network library. * * The poly network is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The poly network is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with The poly network . If not, see <http://www.gnu.org/licenses/>.

* Copyright (C) 2020 The poly network Authors * This file is part of The poly network library. * * The poly network is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The poly network is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with The poly network . If not, see <http://www.gnu.org/licenses/>.

* Copyright (C) 2020 The poly network Authors * This file is part of The poly network library. * * The poly network is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The poly network is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with The poly network . If not, see <http://www.gnu.org/licenses/>.

Package restful privides restful server router

* Copyright (C) 2020 The poly network Authors * This file is part of The poly network library. * * The poly network is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The poly network is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with The poly network . If not, see <http://www.gnu.org/licenses/>.

* Copyright (C) 2020 The poly network Authors * This file is part of The poly network library. * * The poly network is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The poly network is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with The poly network . If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	SUCCESS uint32 = 0
	FAILED  uint32 = 1

	INVALID_METHOD     uint32 = 42001
	INVALID_PARAMS     uint32 = 42002
	ILLEGAL_DATAFORMAT uint32 = 42003
	INTERNAL_ERROR     uint32 = 42004
)

Variables

View Source
var ErrMap = map[uint32]string{
	SUCCESS:            "SUCCESS",
	FAILED:             "FAILED",
	INVALID_METHOD:     "INVALID METHOD",
	INVALID_PARAMS:     "INVALID PARAMS",
	ILLEGAL_DATAFORMAT: "ILLEGAL DATAFORMAT",
	INTERNAL_ERROR:     "INTERNAL_ERROR",
}

Functions

func PackResponse

func PackResponse(errCode uint32) map[string]interface{}

Types

type Action

type Action struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

type ApiServer

type ApiServer interface {
	Start() error
	Stop()
}

func InitRestServer

func InitRestServer(web Web, port uint64, cliAddr string) ApiServer

init restful server

type BroadcastTxReq

type BroadcastTxReq struct {
	RawTx string `json:"raw_tx"`
}

type ChangeAddressReq

type ChangeAddressReq struct {
	Aciton string `json:"aciton"`
	Addr   string `json:"addr"`
}

type GetAllUtxosResp

type GetAllUtxosResp struct {
	Infos []UtxoInfo `json:"infos"`
}

type GetFeePerByteReq

type GetFeePerByteReq struct {
	Level int `json:"level"`
}

type QueryHeaderByHeightParam

type QueryHeaderByHeightParam struct {
	Height uint32 `json:"height"`
}

type QueryUtxosReq

type QueryUtxosReq struct {
	Addr      string `json:"addr"`
	Amount    int64  `json:"amount"`
	Fee       int64  `json:"fee"`
	IsPreExec bool   `json:"is_pre_exec"`
}

type Response

type Response struct {
	Action string      `json:"action"`
	Desc   string      `json:"desc"`
	Error  uint32      `json:"error"`
	Result interface{} `json:"result"`
}

response

type ResponseAllUtxos

type ResponseAllUtxos struct {
	Action string          `json:"action"`
	Desc   string          `json:"desc"`
	Error  uint32          `json:"error"`
	Result GetAllUtxosResp `json:"result"`
}

type RestClient

type RestClient struct {
	Addr string
	// contains filtered or unexported fields
}

func NewRestClient

func NewRestClient(addr string) *RestClient

func (*RestClient) BroadcastTxBySpv

func (self *RestClient) BroadcastTxBySpv(mtx *wire.MsgTx) error

func (*RestClient) ChangeSpvWatchedAddr

func (self *RestClient) ChangeSpvWatchedAddr(addr string, action string) error

func (*RestClient) GetAllUtxosFromSpv

func (self *RestClient) GetAllUtxosFromSpv() ([]UtxoInfo, error)

func (*RestClient) GetCurrentHeightFromSpv

func (self *RestClient) GetCurrentHeightFromSpv() (uint32, error)

func (*RestClient) GetFeeRateFromSpv

func (self *RestClient) GetFeeRateFromSpv(level int) (int64, error)

func (*RestClient) GetHeaderFromSpv

func (self *RestClient) GetHeaderFromSpv(height uint32) (*wire.BlockHeader, error)

func (*RestClient) GetUtxosFromSpv

func (self *RestClient) GetUtxosFromSpv(addr string, amount int64, fee int64, isPreExec bool) ([]btcjson.TransactionInput, int64, error)

func (*RestClient) GetWatchedAddrsFromSpv

func (self *RestClient) GetWatchedAddrsFromSpv() ([]string, error)

func (*RestClient) RollbackSpv

func (self *RestClient) RollbackSpv(time string) error

func (*RestClient) SendGetRequst

func (self *RestClient) SendGetRequst(addr string) ([]byte, error)

func (*RestClient) SendRestRequest

func (self *RestClient) SendRestRequest(addr string, data []byte) ([]byte, error)

func (*RestClient) SetAddr

func (self *RestClient) SetAddr(addr string) *RestClient

func (*RestClient) SetRestClient

func (self *RestClient) SetRestClient(restClient *http.Client) *RestClient

func (*RestClient) UnlockUtxoInSpv

func (self *RestClient) UnlockUtxoInSpv(hash string, index uint32) error

type RollbackReq

type RollbackReq struct {
	Time string `json:"time"`
}

type Route

type Route struct {
	Method  string
	Path    *regexp.Regexp
	Params  []string
	Handler http.HandlerFunc
}

rest router

type Router

type Router struct {
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter(cliHost string) *Router

func (*Router) Connect

func (r *Router) Connect(path string, handler http.HandlerFunc)

func (*Router) Delete

func (r *Router) Delete(path string, handler http.HandlerFunc)

func (*Router) Get

func (r *Router) Get(path string, handler http.HandlerFunc)

func (*Router) Head

func (r *Router) Head(path string, handler http.HandlerFunc)

func (*Router) Options

func (r *Router) Options(path string, handler http.HandlerFunc)

func (*Router) Post

func (r *Router) Post(path string, handler http.HandlerFunc)

func (*Router) Put

func (r *Router) Put(path string, handler http.HandlerFunc)

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Router) Try

func (this *Router) Try(path string, method string) (http.HandlerFunc, paramsMap, error)

type UnlockUtxoReq

type UnlockUtxoReq struct {
	Hash  string `json:"hash"`
	Index uint32 `json:"index"`
}

type UtxoInfo

type UtxoInfo struct {
	Outpoint string `json:"outpoint"`
	Val      int64  `json:"val"`
	IsLock   bool   `json:"is_lock"`
	Height   int32  `json:"height"`
	Script   string `json:"script"`
}

type Web

type Web interface {
	SignTx(map[string]interface{}) map[string]interface{}
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL