-
Notifications
You must be signed in to change notification settings - Fork 1
/
multisig_store.go
70 lines (62 loc) · 2.05 KB
/
multisig_store.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
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package wallet
import (
"github.com/assetcloud/chain/common/db"
"github.com/assetcloud/chain/types"
wcom "github.com/assetcloud/chain/wallet/common"
mtypes "github.com/assetcloud/plugin/plugin/dapp/multisig/types"
)
func newStore(db db.DB) *multisigStore {
return &multisigStore{Store: wcom.NewStore(db)}
}
// multisigStore 多重签名数据库存储操作类
type multisigStore struct {
*wcom.Store
}
//获取指定owner拥有的多重签名地址
func (store *multisigStore) listOwnerAttrsByAddr(addr string) (*mtypes.OwnerAttrs, error) {
if len(addr) == 0 {
bizlog.Error("listMultisigAddrByOwnerAddr addr is nil")
return nil, types.ErrInvalidParam
}
ownerAttrByte, err := store.Get(calcMultisigAddr(addr))
if err != nil {
bizlog.Error("listMultisigAddrByOwnerAddr", "addr", addr, "db Get error ", err)
if err == db.ErrNotFoundInDb {
return nil, types.ErrNotFound
}
return nil, err
}
if nil == ownerAttrByte || len(ownerAttrByte) == 0 {
return nil, types.ErrNotFound
}
var ownerAttrs mtypes.OwnerAttrs
err = types.Decode(ownerAttrByte, &ownerAttrs)
if err != nil {
bizlog.Error("listMultisigAddrByOwnerAddr", "proto.Unmarshal err:", err)
return nil, types.ErrUnmarshal
}
return &ownerAttrs, nil
}
//获取本钱包地址拥有的所有多重签名地址
func (store *multisigStore) listOwnerAttrs() (*mtypes.OwnerAttrs, error) {
list := store.NewListHelper()
ownerbytes := list.PrefixScan(calcPrefixMultisigAddr())
if len(ownerbytes) == 0 {
bizlog.Error("listOwnerAttrs is null")
return nil, types.ErrNotFound
}
var replayOwnerAttrs mtypes.OwnerAttrs
for _, ownerattrbytes := range ownerbytes {
var ownerAttrs mtypes.OwnerAttrs
err := types.Decode(ownerattrbytes, &ownerAttrs)
if err != nil {
bizlog.Error("listOwnerAttrs", "Decode err", err)
continue
}
replayOwnerAttrs.Items = append(replayOwnerAttrs.Items, ownerAttrs.Items...)
}
return &replayOwnerAttrs, nil
}