forked from moneropay/go-monero
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
112 lines (95 loc) · 2.59 KB
/
Copy pathmain.go
File metadata and controls
112 lines (95 loc) · 2.59 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
// This runs against the regtest harness.sh -- adapt for your needs
import (
"context"
"fmt"
"log"
"net/http"
"github.com/bisoncraft/go-monero/old_rpc"
"github.com/bisoncraft/go-monero/rpc"
)
/////////////////////////
// Run Regtest Harness //
/////////////////////////
func main() {
ctx := context.Background()
charlie := rpc.New(rpc.Config{
// charlie address
Address: "http://127.0.0.1:28284/json_rpc",
Client: &http.Client{ /*default no auth HTTP client*/ },
})
// charlie sends 0.000333 XMR -> fred
tr_req := rpc.TransferRequest{
Destinations: []rpc.Destination{
{
Amount: 333000000,
Address: "494aSG3QY1C4PJf7YyDjFc9n2uAuARWSoGQ3hrgPWXtEjgGrYDn2iUw8WJP5Dzm4GuMkY332N9WfbaKfu5tWM3wk8ZeSEC5",
},
},
AccountIndex: 0,
SubaddrIndices: []uint64{0},
Priority: 0,
RingSize: 11,
UnlockTime: 20, // locked tx .. maybe for atomic swap
GetTxKey: true,
}
tr_resp, err := charlie.Transfer(ctx, &tr_req)
if err != nil {
log.Fatal(err)
}
fmt.Println("tx_hash:", tr_resp.TxHash)
daemon := old_rpc.New(old_rpc.Config{
Address: "http://127.0.0.1:18081",
})
// get daemon txs info
gtxs_req := old_rpc.GetTransactionsRequest{
TxsHashes: []string{
tr_resp.TxHash,
},
DecodeAsJson: true,
}
gtxs_resp, err := daemon.GetTransactions(ctx, >xs_req)
if err != nil {
log.Fatal(err)
}
fmt.Println("status:", gtxs_resp.Status)
// try resend tx again direct to daemon - Not Relayed
srt_req := old_rpc.SendRawTransactionRequest{
TxAsHex: gtxs_resp.TxsAsHex[0],
DoNotRelay: false,
}
srt_resp, err := daemon.SendRawTransaction(ctx, &srt_req)
if err != nil {
log.Fatal(err)
}
fmt.Println("status:", srt_resp.Status)
// get mempool
gtp_resp, err := daemon.GetTransactionPool(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println("status:", gtp_resp.Status)
client := rpc.New(rpc.Config{
Address: "http://127.0.0.1:18081/json_rpc",
Client: &http.Client{ /*default no auth HTTP client*/ },
})
// mine to fred
drg_req := rpc.DemonRegtestGenerateRequest{
AmountOfBlocks: 1,
WalletAddress: "494aSG3QY1C4PJf7YyDjFc9n2uAuARWSoGQ3hrgPWXtEjgGrYDn2iUw8WJP5Dzm4GuMkY332N9WfbaKfu5tWM3wk8ZeSEC5",
StartingNonce: 0,
}
drg_resp, err := client.DaemonRegtestGenerate(ctx, &drg_req)
if err != nil {
// if not regtest daemon will say:
// "json2.Error {Code: -13, Message: "Regtest required when generating blocks"}"
log.Fatal(err)
}
fmt.Println("status:", drg_resp.Status)
// get daemon height,etc.
dgi_resp, err := client.DaemonGetInfo(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println("status:", dgi_resp.Status)
}