forked from tigwyk/accept-banano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send.go
43 lines (41 loc) · 944 Bytes
/
send.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
package main
import (
"github.com/tigwyk/accept-banano/internal/banano"
"github.com/cenkalti/log"
"github.com/shopspring/decimal"
)
func sendAll(account, destination, privateKey string) error {
log.Debugln("sending from", account)
info, err := node.AccountInfo(account)
if err != nil {
return err
}
if info.Balance.IsZero() {
return nil
}
var work string
if worknode != nil {
work, err = worknode.RemoteWork(info.Frontier)
if err != nil {
work, err = banano.GenerateWork(info.Frontier, true)
if err != nil {
return err
}
}
} else {
work, err = banano.GenerateWork(info.Frontier, true)
if err != nil {
return err
}
}
block, err := node.BlockCreate(info.Frontier, account, config.Representative, decimal.Zero, destination, privateKey, work)
if err != nil {
return err
}
hash, err := node.Process(block)
if err != nil {
return err
}
log.Debugln("published new block:", hash)
return nil
}