/
g_attach_to_tangle.go
55 lines (49 loc) · 1.48 KB
/
g_attach_to_tangle.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
package gocks
import (
. "github.com/loveandpeople/lp.go/api"
. "github.com/loveandpeople/lp.go/api/integration/samples"
"github.com/loveandpeople/lp.go/bundle"
"github.com/loveandpeople/lp.go/transaction"
. "github.com/loveandpeople/lp.go/trinary"
"gopkg.in/h2non/gock.v1"
"time"
)
func init() {
reqTrytes := make([]Trytes, len(BundleTrytes))
copy(reqTrytes, BundleTrytes)
for i, j := 0, len(reqTrytes)-1; i < j; i, j = i+1, j-1 {
reqTrytes[i], reqTrytes[j] = reqTrytes[j], reqTrytes[i]
}
gock.New(DefaultLocalIRIURI).
Persist().
Post("/").
MatchType("json").
JSON(AttachToTangleCommand{
Command: Command{AttachToTangleCmd},
TrunkTransaction: TrunkTx,
BranchTransaction: BranchTx,
Trytes: reqTrytes,
MinWeightMagnitude: 14,
}).
Reply(200).
JSON(AttachToTangleResponse{Trytes: BundleTrytes})
ts := uint64(time.Now().UnixNano() / int64(time.Second))
entries, err := bundle.TransfersToBundleEntries(ts, bundle.EmptyTransfer)
if err != nil {
panic(err)
}
emptyTxTrytes := transaction.MustTransactionToTrytes(&(bundle.AddEntry(bundle.Bundle{}, entries[0])[0]))
gock.New(DefaultLocalIRIURI).
Persist().
Post("/").
MatchType("json").
JSON(AttachToTangleCommand{
Command: Command{AttachToTangleCmd},
TrunkTransaction: TrunkTx,
BranchTransaction: BranchTx,
Trytes: []Trytes{emptyTxTrytes},
MinWeightMagnitude: 14,
}).
Reply(200).
JSON(AttachToTangleResponse{Trytes: BundleTrytes})
}