-
Notifications
You must be signed in to change notification settings - Fork 13
/
provenance.go
72 lines (57 loc) · 1.7 KB
/
provenance.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
// 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 rpccalls
import (
"github.com/bitmark-inc/bitmarkd/merkle"
"github.com/bitmark-inc/bitmarkd/rpc/bitmark"
)
// ProvenanceData - data for a provenance request
type ProvenanceData struct {
TxId string
Count int
Identities map[string]string
}
// ProvenanceReply - list of transactions in the provenance chain
type ProvenanceReply struct {
Data []provenanceItem `json:"data"`
}
// provenanceItem - transaction record in provenance chain
type provenanceItem struct {
bitmark.ProvenanceRecord
Identity string `json:"_IDENTITY"`
}
// GetProvenance - obtain the provenance chain from a specific transaction id
func (client *Client) GetProvenance(provenanceConfig *ProvenanceData) (*ProvenanceReply, error) {
var txId merkle.Digest
if err := txId.UnmarshalText([]byte(provenanceConfig.TxId)); nil != err {
return nil, err
}
provenanceArgs := bitmark.ProvenanceArguments{
TxId: txId,
Count: provenanceConfig.Count,
}
client.printJson("Provenance Request", provenanceArgs)
var reply bitmark.ProvenanceReply
err := client.client.Call("Bitmark.Provenance", provenanceArgs, &reply)
if nil != err {
return nil, err
}
client.printJson("Provenance Reply", reply)
r := &ProvenanceReply{
Data: make([]provenanceItem, len(reply.Data)),
}
for i, d := range reply.Data {
r.Data[i].ProvenanceRecord = d
m := d.Data.(map[string]interface{})
owner := m["owner"]
if nil == owner {
owner = m["registrant"]
}
if s, ok := owner.(string); ok {
r.Data[i].Identity = provenanceConfig.Identities[s]
}
}
return r, nil
}