-
Notifications
You must be signed in to change notification settings - Fork 13
/
run-blockdecode.go
52 lines (39 loc) · 1001 Bytes
/
run-blockdecode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// SPDX-License-Identifier: ISC
// Copyright (c) 2014-2020 Bitmark Inc.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package main
import (
"encoding/base64"
"fmt"
"github.com/bitmark-inc/bitmarkd/command/bitmark-cli/rpccalls"
"github.com/urfave/cli"
)
func runBlockDecode(c *cli.Context) error {
m := c.App.Metadata["config"].(*metadata)
packed := c.String("packed")
if "" == packed {
return fmt.Errorf("empty packed")
}
p64, err := base64.StdEncoding.DecodeString(packed)
if nil != err {
return err
}
if m.verbose {
fmt.Fprintf(m.e, "packed: %s\n", packed)
}
client, err := rpccalls.NewClient(m.testnet, m.config.Connections[m.connectionOffset], m.verbose, m.e)
if nil != err {
return err
}
defer client.Close()
blockDecodeConfig := &rpccalls.BlockDecodeData{
Packed: p64,
}
response, err := client.DecodeBlock(blockDecodeConfig)
if nil != err {
return err
}
printJson(m.w, response)
return nil
}