From: Outer-God <39217235+Outer-God@users.noreply.github.com> Date: Mon, 15 Mar 2021 07:30:48 +0000 (+0800) Subject: upload (#570) X-Git-Tag: v1.1.9~21 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=8b0a704df94b49b6d764e9a3c6177421c91dc5ee;p=bytom%2Fvapor.git upload (#570) * upload * Update ossClient.go * config * vaporClient * Delete main.go * u * del * Update vaporClient.go * Update vaporClient.go * Update vaporClient.go * Update vaporClient.go * Update config.go * Update vaporClient.go * ossClient * Delete ossClient.go * vaporClient * Delete vaporClient.go Co-authored-by: Welt --- diff --git a/toolbar/apinode/block.go b/toolbar/apinode/block.go index 7b6ae947..8a7cf5ad 100644 --- a/toolbar/apinode/block.go +++ b/toolbar/apinode/block.go @@ -16,6 +16,16 @@ func (n *Node) GetBlockByHeight(height uint64) (*types.Block, error) { return n.getRawBlock(&getRawBlockReq{BlockHeight: height}) } +type getBlockCountResp struct { + BlockCount uint64 `json:"block_count"` +} + +func (n *Node) GetBlockCount() (uint64, error) { + url := "/get-block-count" + res := &getBlockCountResp{} + return res.BlockCount, n.request(url, nil, res) +} + type getRawBlockReq struct { BlockHeight uint64 `json:"block_height"` BlockHash string `json:"block_hash"` diff --git a/toolbar/osssync/config/config.go b/toolbar/osssync/config/config.go new file mode 100644 index 00000000..be4c2a82 --- /dev/null +++ b/toolbar/osssync/config/config.go @@ -0,0 +1,40 @@ +package config + +import ( + "encoding/json" + "os" + + "github.com/bytom/bytom/errors" +) + +// Config represent root of config +type Config struct { + Oss Oss `json:"oss"` + VaporURL string `json:"vapor_url"` +} + +// Oss logs cfg +type Oss struct { + Endpoint string `json:"endpoint"` + AccessKeyID string `json:"access_key_id"` + AccessKeySecret string `json:"access_key_secret"` +} + +// LoadConfig read path file to the config object +func LoadConfig(config interface{}) error { + if len(os.Args) <= 1 { + return errors.New("Please setup the config file path as Args[1]") + } + return LoadConfigByPath(os.Args[1], config) +} + +// LoadConfigByPath read path file to the config object +func LoadConfigByPath(path string, config interface{}) error { + configFile, err := os.Open(path) + if err != nil { + return errors.Wrap(err, "fail to open config file") + } + + defer configFile.Close() + return json.NewDecoder(configFile).Decode(config) +}