-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathmeta.go
72 lines (68 loc) · 2.4 KB
/
meta.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package gobcy
import (
"fmt"
"strconv"
)
//GetMeta gets BlockCypher-stored metadata associated with
//the hash of the given blockchain object. "Kind" describes
//the blockchain object you're querying:
// "addr" (for an address)
// "tx" (for a transaction)
// "block" (for a block)
//If private is false, will retrieve publicly stored metadata.
//If private is true, will retrieve privately stored metadata
//associated with your token.
func (api *API) GetMeta(hash string, kind string, private bool) (meta map[string]string, err error) {
if kind != "addr" && kind != "tx" && kind != "block" {
err = fmt.Errorf("Func GetMeta: kind an invalid type: '%v'. Needs to be 'addr', 'tx', or 'block'", kind)
return
}
params := map[string]string{"private": strconv.FormatBool(private)}
u, err := api.buildURL("/"+kind+"s/"+hash+"/meta", params)
if err != nil {
return
}
err = getResponse(u, &meta)
return
}
//PutMeta puts BlockCypher-stored metadata associated with
//the hash of the given blockchain object. "Kind" describes
//the blockchain object you're querying:
// "addr" (for an address)
// "tx" (for a transaction)
// "block" (for a block)
//If private is false, will set publicly stored metadata.
//If private is true, will set privately stored metadata
//associated with your token.
func (api *API) PutMeta(hash string, kind string, private bool, meta map[string]string) (err error) {
if kind != "addr" && kind != "tx" && kind != "block" {
err = fmt.Errorf("Func PutMeta: kind an invalid type: '%v'. Needs to be 'addr', 'tx', or 'block'", kind)
return
}
params := map[string]string{"private": strconv.FormatBool(private)}
u, err := api.buildURL("/"+kind+"s/"+hash+"/meta", params)
if err != nil {
return
}
err = putResponse(u, &meta)
return
}
//DeleteMeta deletes ALL PRIVATE BlockCypher-stored metadata
//associated with the hash of the given blockchain object.
//"Kind" describes the blockchain object you're querying:
// "addr" (for an address)
// "tx" (for a transaction)
// "block" (for a block)
//Public metadata cannot be deleted; it is immutable.
func (api *API) DeleteMeta(hash string, kind string) (err error) {
if kind != "addr" && kind != "tx" && kind != "block" {
err = fmt.Errorf("Func DeleteMeta: kind an invalid type: '%v'. Needs to be 'addr', 'tx', or 'block'", kind)
return
}
u, err := api.buildURL("/"+kind+"s/"+hash+"/meta", nil)
if err != nil {
return
}
err = deleteResponse(u)
return
}