-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaccount.go
38 lines (35 loc) · 949 Bytes
/
account.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
package main
import (
"encoding/hex"
"errors"
)
type AccountMgr struct {
//AccountID->PrivateKey的映射
accountPrivKey map[string]*PrivKey
//AccountID->PubKey的映射
accountPubKey map[string]*PubKey
}
func NewAccountMgr() *AccountMgr {
return &AccountMgr{
accountPrivKey: make(map[string]*PrivKey),
accountPubKey: make(map[string]*PubKey),
}
}
func (a *AccountMgr) AddNewAccount(id []byte, priv *PrivKey, pub *PubKey) {
a.accountPrivKey[hex.EncodeToString(id)] = priv
a.accountPubKey[hex.EncodeToString(id)] = pub
}
func (a *AccountMgr) GetAccountPubKey(id []byte) (*PubKey, error) {
pubKey, ok := a.accountPubKey[hex.EncodeToString(id)]
if ok {
return pubKey, nil
}
return nil, errors.New("account not found")
}
func (a *AccountMgr) GetAccountPrivKey(id []byte) (*PrivKey, error) {
privKey, ok := a.accountPrivKey[hex.EncodeToString(id)]
if ok {
return privKey, nil
}
return nil, errors.New("account not found")
}