/
mpc_result.go
43 lines (35 loc) · 990 Bytes
/
mpc_result.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
package mpcService
import (
"github.com/ethereum/go-ethereum/log"
"sync"
"github.com/ethereum/go-ethereum/mpcService/protocol"
)
type BaseMpcResult struct {
mu sync.RWMutex
Result map[string]interface{}
}
func createMpcBaseMpcResult() *BaseMpcResult {
return &BaseMpcResult{Result:make(map[string]interface{})}
}
func (result *BaseMpcResult) Initialize(preSetValue ... protocol.MpcValue) {
log.Info("BaseMpcResult.InitializeValue begin")
for i := 0; i < len(preSetValue); i++ {
result.Result[preSetValue[i].Key] = preSetValue[i].Value
}
}
func (mpc *BaseMpcResult) SetValue(key string, value interface{}) error {
mpc.mu.Lock()
defer mpc.mu.Unlock()
mpc.Result[key] = value
return nil
}
func (mpc *BaseMpcResult) GetValue(key string) (interface{}, error) {
mpc.mu.RLock()
defer mpc.mu.RUnlock()
value, exist := mpc.Result[key]
if exist {
return value, nil
}
log.Error("BaseMpcResult GetValue fail." ,"key", key)
return value, protocol.ErrMpcResultExist
}