-
Notifications
You must be signed in to change notification settings - Fork 0
/
WaykichainWallet.go
98 lines (85 loc) · 3.03 KB
/
WaykichainWallet.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
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
package wiccwallet
import (
"wicc_wallet_go/commons"
"encoding/hex"
)
const WAYKI_TESTNET commons.Network = 1
const WAYKI_MAINTNET commons.Network = 2
//创建助记词
func CreateMnemonics() (string){
mn:= commons.NewMnemonicWithLanguage(commons.ENGLISH)
words,err:=mn.GenerateMnemonic()
if err!=nil{
return ""
}
return words
}
//助记词转换地址
func Mnemonic2Address(words string,netType commons.Network)(string){
address := commons.GenerateAddress(words,netType)
return address
}
//助记词转私钥
func Mnemonic2PrivateKey(words string,netType commons.Network)(string){
privateKey := commons.GeneratePrivateKey(words,netType)
return privateKey
}
//私钥转地址
func PrivateKey2Address(words string,netType commons.Network)(string){
address := commons.ImportPrivateKey(words,netType)
return address
}
//注册账户交易签名
func SignRegisterTx(height int64, fees int64,privateKey string) string {
var waykiRegister commons.WaykiRegisterTxParams
waykiRegister.BaseSignTxParams.PrivateKey=privateKey
waykiRegister.BaseSignTxParams.ValidHeight=height
waykiRegister.BaseSignTxParams.Fees=fees
waykiRegister.BaseSignTxParams.TxType=commons.TX_REGISTERACCOUNT
waykiRegister.BaseSignTxParams.Version=1
hash:=waykiRegister.SignTX()
return hash
}
//普通交易签名
func SignCommonTx(value int64,regid string,toAddr string,height int64, fees int64,privateKey string) string {
var waykicommon commons.WaykiCommonTxParams
waykicommon.Value=value
waykicommon.DestAddress=toAddr
waykicommon.BaseSignTxParams.PrivateKey=privateKey
waykicommon.BaseSignTxParams.RegId=regid
waykicommon.BaseSignTxParams.ValidHeight=height
waykicommon.BaseSignTxParams.Fees=fees
waykicommon.BaseSignTxParams.TxType=commons.TX_COMMON
waykicommon.BaseSignTxParams.Version=1
hash:=waykicommon.SignTX()
return hash
}
//投票交易签名
func SignDelegateTx(regid string,height int64, fees int64,privateKey string,votes []commons.OperVoteFund) string {
var waykiDelegate commons.WaykiDelegateTxParams
waykiDelegate.BaseSignTxParams.PrivateKey=privateKey
waykiDelegate.BaseSignTxParams.RegId=regid
waykiDelegate.BaseSignTxParams.ValidHeight=height
waykiDelegate.BaseSignTxParams.Fees=fees
waykiDelegate.BaseSignTxParams.TxType=commons.TX_DELEGATE
waykiDelegate.BaseSignTxParams.Version=1
waykiDelegate.OperVoteFunds=votes
hash:=waykiDelegate.SignTX()
return hash
}
//智能合约交易签名
func SignContractTx(value int64,height int64, fees int64,privateKey string,regId string,appid string,contractStr string) string {
var waykiContract commons.WaykiContractTxParams
waykiContract.Value=value
waykiContract.BaseSignTxParams.PrivateKey=privateKey
waykiContract.BaseSignTxParams.RegId=regId
waykiContract.Appid=appid
waykiContract.BaseSignTxParams.ValidHeight=height
waykiContract.BaseSignTxParams.Fees=fees
waykiContract.BaseSignTxParams.TxType=commons.TX_CONTRACT
waykiContract.BaseSignTxParams.Version=1
binary,_:=hex.DecodeString(contractStr)
waykiContract.ContractBytes= []byte(binary)
hash:=waykiContract.SignTX()
return hash
}