OSDN Git Service

upload (#570)
authorOuter-God <39217235+Outer-God@users.noreply.github.com>
Mon, 15 Mar 2021 07:30:48 +0000 (15:30 +0800)
committerGitHub <noreply@github.com>
Mon, 15 Mar 2021 07:30:48 +0000 (15:30 +0800)
* 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 <L5Accelerator@users.noreply.github.com>
toolbar/apinode/block.go
toolbar/osssync/config/config.go [new file with mode: 0644]

index 7b6ae94..8a7cf5a 100644 (file)
@@ -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 (file)
index 0000000..be4c2a8
--- /dev/null
@@ -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)
+}