-
Notifications
You must be signed in to change notification settings - Fork 3
/
s2m.go
64 lines (54 loc) · 1.41 KB
/
s2m.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
package main
import (
"math"
"github.com/astaxie/beego/logs"
"github.com/btcsuite/btcd/wire"
)
func s2mTx(recursion bool) {
logs.Info("EXEC s2mTx(%t)", recursion)
dust := conf.DefaultInt("tx::dust", DefaultDust)
iteration := conf.DefaultInt("tx::output_limit", OutputLimit)
for reference, amount := range input {
// avoid to create a coin with low amount than dust
// side effect: make coin more nearly amount at the same time
// todo notice: The number of its tx_out may be not the specified output_limit
// because of maxSplit judgement
var maxSplit int
if dust != 0 {
maxSplit = int(amount*math.Pow10(8)) / dust
}
if maxSplit == 0 {
continue
}
txin := wire.TxIn{
PreviousOutPoint: wire.OutPoint{
Hash: reference.hash,
Index: reference.index,
},
Sequence: 0xffffff, // default value
}
s2m.TxIn[0] = &txin
pkScript := getRandScriptPubKey()
if pkScript == nil {
panic("no account in output...")
}
bak := iteration
if maxSplit < bak {
bak = maxSplit
}
splitValue := int(amount*math.Pow10(8))/bak - fee
if splitValue < 0 {
continue
}
s2m.TxOut = make([]*wire.TxOut, bak)
for i := 0; i < int(bak); i++ {
out := wire.TxOut{
Value: int64(splitValue), // transaction fee
PkScript: pkScript,
}
s2m.TxOut[i] = &out
}
// no assignment for tx.LockTime(default 0)
signAndSendTx(s2m, []ref{reference}, int(bak), recursion)
}
}