forked from build-trust/ockam
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03_submit_claim.go
More file actions
60 lines (48 loc) · 1.49 KB
/
Copy path03_submit_claim.go
File metadata and controls
60 lines (48 loc) · 1.49 KB
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
// +build ignore
package main
import (
"fmt"
"os"
"github.com/ockam-network/ockam/claim"
"github.com/ockam-network/ockam/entity"
"github.com/ockam-network/ockam/key/ed25519"
"github.com/ockam-network/ockam/node"
"github.com/ockam-network/ockam/node/remote/http"
)
func main() {
// create a local ockam node and give it a way to find peers on the ockam test network
ockamNode, err := node.New(node.PeerDiscoverer(http.Discoverer("test.ockam.network", 26657)))
exitOnError(err)
// ask the node to find peers and sync with network state
err = ockamNode.Sync()
exitOnError(err)
// get a reference to the chain the node is synced to
ockamChain := ockamNode.Chain()
fmt.Printf("Chain ID: %s\n", ockamChain.ID())
// create a new ed25519 signer
signer, err := ed25519.New()
exitOnError(err)
// create a new ockam entity to represent a temperature sensor
temperatureSensor, err := entity.New(
entity.Attributes{"name": "Temperature Sensor"},
entity.Signer(signer),
)
exitOnError(err)
// create a temperature claim with this new sensor entity as both the issuer and the subject of the claim
temperatureClaim, err := claim.New(
claim.Data{"temperature": 100},
claim.Issuer(temperatureSensor),
claim.Subject(temperatureSensor),
)
exitOnError(err)
// submit the claim to be
err = ockamChain.Submit(temperatureClaim)
exitOnError(err)
fmt.Printf("Submitted - " + temperatureClaim.ID())
}
func exitOnError(err error) {
if err != nil {
fmt.Fprintf(os.Stderr, "%+v\n", err)
os.Exit(1)
}
}