Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
0b8360b0
Commit
0b8360b0
authored
Aug 30, 2021
by
jiangpeng
Committed by
33cn
Aug 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replace proto Marshal with types.Encode
parent
6f55ad81
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
21 additions
and
65 deletions
+21
-65
account.go
plugin/dapp/evm/executor/vm/state/account.go
+5
-25
privacy.go
plugin/dapp/privacy/wallet/privacy.go
+1
-6
privacystore.go
plugin/dapp/privacy/wallet/privacystore.go
+2
-10
database.go
plugin/store/mpt/db/database.go
+2
-6
hasher.go
plugin/store/mpt/db/hasher.go
+2
-5
iterator.go
plugin/store/mpt/db/iterator.go
+2
-2
node.go
plugin/store/mpt/db/node.go
+3
-6
node_test.go
plugin/store/mpt/db/node_test.go
+2
-3
proof.go
plugin/store/mpt/db/proof.go
+2
-2
No files found.
plugin/dapp/evm/executor/vm/state/account.go
View file @
0b8360b0
...
...
@@ -118,11 +118,7 @@ func (ca *ContractAccount) updateStorageHash() {
for
k
,
v
:=
range
ca
.
State
.
GetStorage
()
{
state
.
Storage
[
k
]
=
v
}
ret
,
err
:=
proto
.
Marshal
(
state
)
if
err
!=
nil
{
log15
.
Error
(
"marshal contract state data error"
,
"error"
,
err
)
return
}
ret
:=
types
.
Encode
(
state
)
ca
.
State
.
StorageHash
=
common
.
ToHash
(
ret
)
.
Bytes
()
}
...
...
@@ -242,43 +238,27 @@ func (ca *ContractAccount) GetExecName() string {
// GetDataKV 合约固定数据,包含合约代码,以及代码哈希
func
(
ca
*
ContractAccount
)
GetDataKV
()
(
kvSet
[]
*
types
.
KeyValue
)
{
ca
.
Data
.
Addr
=
ca
.
Addr
datas
,
err
:=
proto
.
Marshal
(
&
ca
.
Data
)
if
err
!=
nil
{
log15
.
Error
(
"marshal contract data error!"
,
"addr"
,
ca
.
Addr
,
"error"
,
err
)
return
}
datas
:=
types
.
Encode
(
&
ca
.
Data
)
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
ca
.
GetDataKey
(),
Value
:
datas
})
return
}
// GetStateKV 获取合约状态数据,包含nonce、是否自杀、存储哈希、存储数据
func
(
ca
*
ContractAccount
)
GetStateKV
()
(
kvSet
[]
*
types
.
KeyValue
)
{
datas
,
err
:=
proto
.
Marshal
(
&
ca
.
State
)
if
err
!=
nil
{
log15
.
Error
(
"marshal contract state error!"
,
"addr"
,
ca
.
Addr
,
"error"
,
err
)
return
}
datas
:=
types
.
Encode
(
&
ca
.
State
)
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
ca
.
GetStateKey
(),
Value
:
datas
})
return
}
// BuildDataLog 构建变更日志
func
(
ca
*
ContractAccount
)
BuildDataLog
()
(
log
*
types
.
ReceiptLog
)
{
datas
,
err
:=
proto
.
Marshal
(
&
ca
.
Data
)
if
err
!=
nil
{
log15
.
Error
(
"marshal contract data error!"
,
"addr"
,
ca
.
Addr
,
"error"
,
err
)
return
}
datas
:=
types
.
Encode
(
&
ca
.
Data
)
return
&
types
.
ReceiptLog
{
Ty
:
evmtypes
.
TyLogContractData
,
Log
:
datas
}
}
// BuildStateLog 构建变更日志
func
(
ca
*
ContractAccount
)
BuildStateLog
()
(
log
*
types
.
ReceiptLog
)
{
datas
,
err
:=
proto
.
Marshal
(
&
ca
.
State
)
if
err
!=
nil
{
log15
.
Error
(
"marshal contract state log error!"
,
"addr"
,
ca
.
Addr
,
"error"
,
err
)
return
}
datas
:=
types
.
Encode
(
&
ca
.
State
)
return
&
types
.
ReceiptLog
{
Ty
:
evmtypes
.
TyLogContractState
,
Log
:
datas
}
}
...
...
plugin/dapp/privacy/wallet/privacy.go
View file @
0b8360b0
...
...
@@ -24,7 +24,6 @@ import (
wcom
"github.com/33cn/chain33/wallet/common"
privacy
"github.com/33cn/plugin/plugin/dapp/privacy/crypto"
privacytypes
"github.com/33cn/plugin/plugin/dapp/privacy/types"
"github.com/golang/protobuf/proto"
)
func
(
policy
*
privacyPolicy
)
rescanAllTxAddToUpdateUTXOs
()
{
...
...
@@ -984,11 +983,7 @@ func (policy *privacyPolicy) buildAndStoreWalletTxDetail(param *buildStoreWallet
txdetail
.
Amount
,
_
=
txInfo
.
tx
.
Amount
()
txdetail
.
Fromaddr
=
param
.
addr
txdetailbyte
,
err
:=
proto
.
Marshal
(
&
txdetail
)
if
err
!=
nil
{
bizlog
.
Error
(
"buildAndStoreWalletTxDetail err"
,
"Height"
,
txInfo
.
blockHeight
,
"txHash"
,
txInfo
.
txHashHex
)
return
}
txdetailbyte
:=
types
.
Encode
(
&
txdetail
)
txInfo
.
batch
.
Set
(
key
,
txdetailbyte
)
//额外存储可以快速定位到接收隐私的交易
...
...
plugin/dapp/privacy/wallet/privacystore.go
View file @
0b8360b0
...
...
@@ -140,11 +140,7 @@ func (store *privacyStore) setWalletAccountPrivacy(addr string, privacy *privacy
return
types
.
ErrInvalidParam
}
privacybyte
,
err
:=
proto
.
Marshal
(
privacy
)
if
err
!=
nil
{
bizlog
.
Error
(
"SetWalletAccountPrivacy proto.Marshal err!"
,
"err"
,
err
)
return
types
.
ErrMarshal
}
privacybyte
:=
types
.
Encode
(
privacy
)
newbatch
:=
store
.
NewBatch
(
true
)
newbatch
.
Set
(
calcPrivacyAddrKey
(
addr
),
privacybyte
)
...
...
@@ -652,11 +648,7 @@ func (store *privacyStore) selectCurrentWalletPrivacyTx(txDetal *types.Transacti
//2.calcUTXOKey4TokenAddr-->calcUTXOKey,创建kv,方便查询现在某个地址下某种token的可用utxo
func
(
store
*
privacyStore
)
setUTXO
(
utxoInfo
*
privacytypes
.
PrivacyDBStore
,
txHash
string
,
newbatch
db
.
Batch
)
error
{
privacyStorebyte
,
err
:=
proto
.
Marshal
(
utxoInfo
)
if
err
!=
nil
{
bizlog
.
Error
(
"setUTXO proto.Marshal err!"
,
"err"
,
err
)
return
types
.
ErrMarshal
}
privacyStorebyte
:=
types
.
Encode
(
utxoInfo
)
outIndex
:=
int
(
utxoInfo
.
OutIndex
)
utxoKey
:=
calcUTXOKey
(
txHash
,
outIndex
)
bizlog
.
Debug
(
"setUTXO"
,
"addr"
,
utxoInfo
.
Owner
,
"tx with hash"
,
txHash
,
"amount:"
,
utxoInfo
.
Amount
/
store
.
GetCoinPrecision
())
...
...
plugin/store/mpt/db/database.go
View file @
0b8360b0
...
...
@@ -22,12 +22,12 @@ package mpt
import
(
"fmt"
"github.com/33cn/chain33/types"
"sync"
"time"
"github.com/33cn/chain33/common"
dbm
"github.com/33cn/chain33/common/db"
proto
"github.com/golang/protobuf/proto"
)
// secureKeyPrefix is the database key prefix used to store trie node preimages.
...
...
@@ -98,11 +98,7 @@ type cachedNode struct {
}
func
(
n
*
cachedNode
)
proto
()
[]
byte
{
blob
,
err
:=
proto
.
Marshal
(
n
.
node
.
create
())
if
err
!=
nil
{
panic
(
err
)
}
return
blob
return
types
.
Encode
(
n
.
node
.
create
())
}
// expandNode traverses the node hierarchy of a collapsed storage node and converts
...
...
plugin/store/mpt/db/hasher.go
View file @
0b8360b0
...
...
@@ -21,12 +21,12 @@
package
mpt
import
(
"github.com/33cn/chain33/types"
"hash"
"sync"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/crypto/sha3"
proto
"github.com/golang/protobuf/proto"
)
type
hasher
struct
{
...
...
@@ -179,10 +179,7 @@ func (h *hasher) store(n node, db *Database, force bool) (node, error) {
return
n
,
nil
// Nodes smaller than 64 bytes are stored inside their parent
}
nn
:=
n
.
create
()
data
,
err
:=
proto
.
Marshal
(
nn
)
if
err
!=
nil
{
panic
(
"encode error: "
+
err
.
Error
())
}
data
:=
types
.
Encode
(
nn
)
// Larger nodes are replaced by their hash and stored in the database.
hash
,
_
:=
n
.
cache
()
if
hash
.
HashNode
==
nil
{
...
...
plugin/store/mpt/db/iterator.go
View file @
0b8360b0
...
...
@@ -24,9 +24,9 @@ import (
"bytes"
"container/heap"
"errors"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/common"
proto
"github.com/golang/protobuf/proto"
)
// Iterator is a key-value trie iterator that traverses a Trie.
...
...
@@ -192,7 +192,7 @@ func (it *nodeIterator) LeafProof() [][]byte {
node
,
_
,
_
:=
hasher
.
hashChildren
(
item
.
node
,
nil
)
hashed
,
_
:=
hasher
.
store
(
node
,
nil
,
false
)
if
_
,
ok
:=
hashed
.
(
hashNode
);
ok
||
i
==
0
{
enc
,
_
:=
proto
.
Marshal
(
node
.
create
())
enc
:=
types
.
Encode
(
node
.
create
())
proofs
=
append
(
proofs
,
enc
)
}
}
...
...
plugin/store/mpt/db/node.go
View file @
0b8360b0
...
...
@@ -22,6 +22,7 @@ package mpt
import
(
"fmt"
"github.com/33cn/chain33/types"
"io"
"strings"
...
...
@@ -75,12 +76,8 @@ type valueNode struct {
// EncodeRLP encodes a full node into the consensus RLP format.
func
(
n
*
fullNode
)
EncodeProto
(
w
io
.
Writer
)
error
{
node
:=
n
.
create
()
data
,
err
:=
proto
.
Marshal
(
node
)
if
err
!=
nil
{
return
err
}
_
,
err
=
w
.
Write
(
data
)
data
:=
types
.
Encode
(
n
.
create
())
_
,
err
:=
w
.
Write
(
data
)
return
err
}
...
...
plugin/store/mpt/db/node_test.go
View file @
0b8360b0
...
...
@@ -21,9 +21,9 @@
package
mpt
import
(
"github.com/33cn/chain33/types"
"testing"
proto
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/assert"
)
...
...
@@ -68,7 +68,6 @@ func TestCanUnload(t *testing.T) {
func
TestNodeProto
(
t
*
testing
.
T
)
{
n
:=
&
Node
{
Value
:
&
Node_Full
{
Full
:
&
FullNode
{}}}
d
,
err
:=
proto
.
Marshal
(
n
)
assert
.
Nil
(
t
,
nil
,
err
)
d
:=
types
.
Encode
(
n
)
assert
.
Equal
(
t
,
2
,
len
(
d
))
}
plugin/store/mpt/db/proof.go
View file @
0b8360b0
...
...
@@ -23,10 +23,10 @@ package mpt
import
(
"bytes"
"fmt"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/common"
dbm
"github.com/33cn/chain33/common/db"
proto
"github.com/golang/protobuf/proto"
)
// Prove constructs a merkle proof for key. The result contains all encoded nodes
...
...
@@ -79,7 +79,7 @@ func (t *Trie) Prove(key []byte, fromLevel uint, proofDb dbm.DB) error {
if
fromLevel
>
0
{
fromLevel
--
}
else
{
enc
,
_
:=
proto
.
Marshal
(
n
.
create
())
enc
:=
types
.
Encode
(
n
.
create
())
if
!
ok
{
hash
=
createHashNode
(
common
.
Sha3
(
enc
))
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment