-
Notifications
You must be signed in to change notification settings - Fork 13
/
fullprovenance.go
70 lines (55 loc) · 1.81 KB
/
fullprovenance.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
// SPDX-License-Identifier: ISC
// Copyright (c) 2014-2021 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"
)
// FullProvenanceData - data for a full provenance request
type FullProvenanceData struct {
BitmarkId string
Identities map[string]string
}
// FullProvenanceReply - list of transactions in the full provenance chain
type FullProvenanceReply struct {
Data []fullProvenanceItem `json:"data"`
}
// fullProvenanceItem - transaction record in full provenance chain
type fullProvenanceItem struct {
bitmark.FullProvenanceRecord
Identity string `json:"_IDENTITY,omitempty"`
}
// GetFullProvenance - obtain the full provenance chain from a specific bitmark id
func (client *Client) GetFullProvenance(fullProvenanceConfig *FullProvenanceData) (*FullProvenanceReply, error) {
var bitmarkId merkle.Digest
if err := bitmarkId.UnmarshalText([]byte(fullProvenanceConfig.BitmarkId)); nil != err {
return nil, err
}
fullProvenanceArgs := bitmark.FullProvenanceArguments{
BitmarkId: bitmarkId,
}
client.printJson("Full Provenance Request", fullProvenanceArgs)
var reply bitmark.FullProvenanceReply
err := client.client.Call("Bitmark.FullProvenance", fullProvenanceArgs, &reply)
if nil != err {
return nil, err
}
client.printJson("Full Provenance Reply", reply)
r := &FullProvenanceReply{
Data: make([]fullProvenanceItem, len(reply.Data)),
}
for i, d := range reply.Data {
r.Data[i].FullProvenanceRecord = 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 = fullProvenanceConfig.Identities[s]
}
}
return r, nil
}