forked from skycoin/skycoin-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
50 lines (38 loc) · 1.02 KB
/
api.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
package mobile
import (
"encoding/json"
"encoding/hex"
"github.com/skycoin/skycoin-lite/liteclient"
"github.com/skycoin/skycoin/src/cipher/go-bip39"
)
func GetAddresses(seed string, num int) (addr string, err error) {
defer func() {
r := recover()
err, _ = r.(error)
}()
hexSeed := hex.EncodeToString([]byte(seed))
addresses := liteclient.GenerateAddresses(hexSeed, num);
byteaddr, err := json.Marshal(addresses)
if err != nil {
return "", err
}
addr = string(byteaddr)
return addr, nil
}
// PrepareTransaction receives inputs and outputs and returns a signed transaction
// inputsBody and outputsBody are JSONified arrays of TransactionInput and TransactionOutput.
func PrepareTransaction(inputsBody string, outputsBody string) (tx string, err error) {
defer func() {
r := recover()
err, _ = r.(error)
}()
tx = liteclient.PrepareTransaction(inputsBody, outputsBody)
return
}
func NewWordSeed() (string, error) {
seed, err := bip39.NewDefaultMnemonic()
if err != nil {
panic(err)
}
return seed, nil
}