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() {
...
@@ -118,11 +118,7 @@ func (ca *ContractAccount) updateStorageHash() {
for
k
,
v
:=
range
ca
.
State
.
GetStorage
()
{
for
k
,
v
:=
range
ca
.
State
.
GetStorage
()
{
state
.
Storage
[
k
]
=
v
state
.
Storage
[
k
]
=
v
}
}
ret
,
err
:=
proto
.
Marshal
(
state
)
ret
:=
types
.
Encode
(
state
)
if
err
!=
nil
{
log15
.
Error
(
"marshal contract state data error"
,
"error"
,
err
)
return
}
ca
.
State
.
StorageHash
=
common
.
ToHash
(
ret
)
.
Bytes
()
ca
.
State
.
StorageHash
=
common
.
ToHash
(
ret
)
.
Bytes
()
}
}
...
@@ -242,43 +238,27 @@ func (ca *ContractAccount) GetExecName() string {
...
@@ -242,43 +238,27 @@ func (ca *ContractAccount) GetExecName() string {
// GetDataKV 合约固定数据,包含合约代码,以及代码哈希
// GetDataKV 合约固定数据,包含合约代码,以及代码哈希
func
(
ca
*
ContractAccount
)
GetDataKV
()
(
kvSet
[]
*
types
.
KeyValue
)
{
func
(
ca
*
ContractAccount
)
GetDataKV
()
(
kvSet
[]
*
types
.
KeyValue
)
{
ca
.
Data
.
Addr
=
ca
.
Addr
ca
.
Data
.
Addr
=
ca
.
Addr
datas
,
err
:=
proto
.
Marshal
(
&
ca
.
Data
)
datas
:=
types
.
Encode
(
&
ca
.
Data
)
if
err
!=
nil
{
log15
.
Error
(
"marshal contract data error!"
,
"addr"
,
ca
.
Addr
,
"error"
,
err
)
return
}
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
ca
.
GetDataKey
(),
Value
:
datas
})
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
ca
.
GetDataKey
(),
Value
:
datas
})
return
return
}
}
// GetStateKV 获取合约状态数据,包含nonce、是否自杀、存储哈希、存储数据
// GetStateKV 获取合约状态数据,包含nonce、是否自杀、存储哈希、存储数据
func
(
ca
*
ContractAccount
)
GetStateKV
()
(
kvSet
[]
*
types
.
KeyValue
)
{
func
(
ca
*
ContractAccount
)
GetStateKV
()
(
kvSet
[]
*
types
.
KeyValue
)
{
datas
,
err
:=
proto
.
Marshal
(
&
ca
.
State
)
datas
:=
types
.
Encode
(
&
ca
.
State
)
if
err
!=
nil
{
log15
.
Error
(
"marshal contract state error!"
,
"addr"
,
ca
.
Addr
,
"error"
,
err
)
return
}
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
ca
.
GetStateKey
(),
Value
:
datas
})
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
ca
.
GetStateKey
(),
Value
:
datas
})
return
return
}
}
// BuildDataLog 构建变更日志
// BuildDataLog 构建变更日志
func
(
ca
*
ContractAccount
)
BuildDataLog
()
(
log
*
types
.
ReceiptLog
)
{
func
(
ca
*
ContractAccount
)
BuildDataLog
()
(
log
*
types
.
ReceiptLog
)
{
datas
,
err
:=
proto
.
Marshal
(
&
ca
.
Data
)
datas
:=
types
.
Encode
(
&
ca
.
Data
)
if
err
!=
nil
{
log15
.
Error
(
"marshal contract data error!"
,
"addr"
,
ca
.
Addr
,
"error"
,
err
)
return
}
return
&
types
.
ReceiptLog
{
Ty
:
evmtypes
.
TyLogContractData
,
Log
:
datas
}
return
&
types
.
ReceiptLog
{
Ty
:
evmtypes
.
TyLogContractData
,
Log
:
datas
}
}
}
// BuildStateLog 构建变更日志
// BuildStateLog 构建变更日志
func
(
ca
*
ContractAccount
)
BuildStateLog
()
(
log
*
types
.
ReceiptLog
)
{
func
(
ca
*
ContractAccount
)
BuildStateLog
()
(
log
*
types
.
ReceiptLog
)
{
datas
,
err
:=
proto
.
Marshal
(
&
ca
.
State
)
datas
:=
types
.
Encode
(
&
ca
.
State
)
if
err
!=
nil
{
log15
.
Error
(
"marshal contract state log error!"
,
"addr"
,
ca
.
Addr
,
"error"
,
err
)
return
}
return
&
types
.
ReceiptLog
{
Ty
:
evmtypes
.
TyLogContractState
,
Log
:
datas
}
return
&
types
.
ReceiptLog
{
Ty
:
evmtypes
.
TyLogContractState
,
Log
:
datas
}
}
}
...
...
plugin/dapp/privacy/wallet/privacy.go
View file @
0b8360b0
...
@@ -24,7 +24,6 @@ import (
...
@@ -24,7 +24,6 @@ import (
wcom
"github.com/33cn/chain33/wallet/common"
wcom
"github.com/33cn/chain33/wallet/common"
privacy
"github.com/33cn/plugin/plugin/dapp/privacy/crypto"
privacy
"github.com/33cn/plugin/plugin/dapp/privacy/crypto"
privacytypes
"github.com/33cn/plugin/plugin/dapp/privacy/types"
privacytypes
"github.com/33cn/plugin/plugin/dapp/privacy/types"
"github.com/golang/protobuf/proto"
)
)
func
(
policy
*
privacyPolicy
)
rescanAllTxAddToUpdateUTXOs
()
{
func
(
policy
*
privacyPolicy
)
rescanAllTxAddToUpdateUTXOs
()
{
...
@@ -984,11 +983,7 @@ func (policy *privacyPolicy) buildAndStoreWalletTxDetail(param *buildStoreWallet
...
@@ -984,11 +983,7 @@ func (policy *privacyPolicy) buildAndStoreWalletTxDetail(param *buildStoreWallet
txdetail
.
Amount
,
_
=
txInfo
.
tx
.
Amount
()
txdetail
.
Amount
,
_
=
txInfo
.
tx
.
Amount
()
txdetail
.
Fromaddr
=
param
.
addr
txdetail
.
Fromaddr
=
param
.
addr
txdetailbyte
,
err
:=
proto
.
Marshal
(
&
txdetail
)
txdetailbyte
:=
types
.
Encode
(
&
txdetail
)
if
err
!=
nil
{
bizlog
.
Error
(
"buildAndStoreWalletTxDetail err"
,
"Height"
,
txInfo
.
blockHeight
,
"txHash"
,
txInfo
.
txHashHex
)
return
}
txInfo
.
batch
.
Set
(
key
,
txdetailbyte
)
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
...
@@ -140,11 +140,7 @@ func (store *privacyStore) setWalletAccountPrivacy(addr string, privacy *privacy
return
types
.
ErrInvalidParam
return
types
.
ErrInvalidParam
}
}
privacybyte
,
err
:=
proto
.
Marshal
(
privacy
)
privacybyte
:=
types
.
Encode
(
privacy
)
if
err
!=
nil
{
bizlog
.
Error
(
"SetWalletAccountPrivacy proto.Marshal err!"
,
"err"
,
err
)
return
types
.
ErrMarshal
}
newbatch
:=
store
.
NewBatch
(
true
)
newbatch
:=
store
.
NewBatch
(
true
)
newbatch
.
Set
(
calcPrivacyAddrKey
(
addr
),
privacybyte
)
newbatch
.
Set
(
calcPrivacyAddrKey
(
addr
),
privacybyte
)
...
@@ -652,11 +648,7 @@ func (store *privacyStore) selectCurrentWalletPrivacyTx(txDetal *types.Transacti
...
@@ -652,11 +648,7 @@ func (store *privacyStore) selectCurrentWalletPrivacyTx(txDetal *types.Transacti
//2.calcUTXOKey4TokenAddr-->calcUTXOKey,创建kv,方便查询现在某个地址下某种token的可用utxo
//2.calcUTXOKey4TokenAddr-->calcUTXOKey,创建kv,方便查询现在某个地址下某种token的可用utxo
func
(
store
*
privacyStore
)
setUTXO
(
utxoInfo
*
privacytypes
.
PrivacyDBStore
,
txHash
string
,
newbatch
db
.
Batch
)
error
{
func
(
store
*
privacyStore
)
setUTXO
(
utxoInfo
*
privacytypes
.
PrivacyDBStore
,
txHash
string
,
newbatch
db
.
Batch
)
error
{
privacyStorebyte
,
err
:=
proto
.
Marshal
(
utxoInfo
)
privacyStorebyte
:=
types
.
Encode
(
utxoInfo
)
if
err
!=
nil
{
bizlog
.
Error
(
"setUTXO proto.Marshal err!"
,
"err"
,
err
)
return
types
.
ErrMarshal
}
outIndex
:=
int
(
utxoInfo
.
OutIndex
)
outIndex
:=
int
(
utxoInfo
.
OutIndex
)
utxoKey
:=
calcUTXOKey
(
txHash
,
outIndex
)
utxoKey
:=
calcUTXOKey
(
txHash
,
outIndex
)
bizlog
.
Debug
(
"setUTXO"
,
"addr"
,
utxoInfo
.
Owner
,
"tx with hash"
,
txHash
,
"amount:"
,
utxoInfo
.
Amount
/
store
.
GetCoinPrecision
())
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
...
@@ -22,12 +22,12 @@ package mpt
import
(
import
(
"fmt"
"fmt"
"github.com/33cn/chain33/types"
"sync"
"sync"
"time"
"time"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common"
dbm
"github.com/33cn/chain33/common/db"
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.
// secureKeyPrefix is the database key prefix used to store trie node preimages.
...
@@ -98,11 +98,7 @@ type cachedNode struct {
...
@@ -98,11 +98,7 @@ type cachedNode struct {
}
}
func
(
n
*
cachedNode
)
proto
()
[]
byte
{
func
(
n
*
cachedNode
)
proto
()
[]
byte
{
blob
,
err
:=
proto
.
Marshal
(
n
.
node
.
create
())
return
types
.
Encode
(
n
.
node
.
create
())
if
err
!=
nil
{
panic
(
err
)
}
return
blob
}
}
// expandNode traverses the node hierarchy of a collapsed storage node and converts
// 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 @@
...
@@ -21,12 +21,12 @@
package
mpt
package
mpt
import
(
import
(
"github.com/33cn/chain33/types"
"hash"
"hash"
"sync"
"sync"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/crypto/sha3"
"github.com/33cn/chain33/common/crypto/sha3"
proto
"github.com/golang/protobuf/proto"
)
)
type
hasher
struct
{
type
hasher
struct
{
...
@@ -179,10 +179,7 @@ func (h *hasher) store(n node, db *Database, force bool) (node, error) {
...
@@ -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
return
n
,
nil
// Nodes smaller than 64 bytes are stored inside their parent
}
}
nn
:=
n
.
create
()
nn
:=
n
.
create
()
data
,
err
:=
proto
.
Marshal
(
nn
)
data
:=
types
.
Encode
(
nn
)
if
err
!=
nil
{
panic
(
"encode error: "
+
err
.
Error
())
}
// Larger nodes are replaced by their hash and stored in the database.
// Larger nodes are replaced by their hash and stored in the database.
hash
,
_
:=
n
.
cache
()
hash
,
_
:=
n
.
cache
()
if
hash
.
HashNode
==
nil
{
if
hash
.
HashNode
==
nil
{
...
...
plugin/store/mpt/db/iterator.go
View file @
0b8360b0
...
@@ -24,9 +24,9 @@ import (
...
@@ -24,9 +24,9 @@ import (
"bytes"
"bytes"
"container/heap"
"container/heap"
"errors"
"errors"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common"
proto
"github.com/golang/protobuf/proto"
)
)
// Iterator is a key-value trie iterator that traverses a Trie.
// Iterator is a key-value trie iterator that traverses a Trie.
...
@@ -192,7 +192,7 @@ func (it *nodeIterator) LeafProof() [][]byte {
...
@@ -192,7 +192,7 @@ func (it *nodeIterator) LeafProof() [][]byte {
node
,
_
,
_
:=
hasher
.
hashChildren
(
item
.
node
,
nil
)
node
,
_
,
_
:=
hasher
.
hashChildren
(
item
.
node
,
nil
)
hashed
,
_
:=
hasher
.
store
(
node
,
nil
,
false
)
hashed
,
_
:=
hasher
.
store
(
node
,
nil
,
false
)
if
_
,
ok
:=
hashed
.
(
hashNode
);
ok
||
i
==
0
{
if
_
,
ok
:=
hashed
.
(
hashNode
);
ok
||
i
==
0
{
enc
,
_
:=
proto
.
Marshal
(
node
.
create
())
enc
:=
types
.
Encode
(
node
.
create
())
proofs
=
append
(
proofs
,
enc
)
proofs
=
append
(
proofs
,
enc
)
}
}
}
}
...
...
plugin/store/mpt/db/node.go
View file @
0b8360b0
...
@@ -22,6 +22,7 @@ package mpt
...
@@ -22,6 +22,7 @@ package mpt
import
(
import
(
"fmt"
"fmt"
"github.com/33cn/chain33/types"
"io"
"io"
"strings"
"strings"
...
@@ -75,12 +76,8 @@ type valueNode struct {
...
@@ -75,12 +76,8 @@ type valueNode struct {
// EncodeRLP encodes a full node into the consensus RLP format.
// EncodeRLP encodes a full node into the consensus RLP format.
func
(
n
*
fullNode
)
EncodeProto
(
w
io
.
Writer
)
error
{
func
(
n
*
fullNode
)
EncodeProto
(
w
io
.
Writer
)
error
{
node
:=
n
.
create
()
data
:=
types
.
Encode
(
n
.
create
())
data
,
err
:=
proto
.
Marshal
(
node
)
_
,
err
:=
w
.
Write
(
data
)
if
err
!=
nil
{
return
err
}
_
,
err
=
w
.
Write
(
data
)
return
err
return
err
}
}
...
...
plugin/store/mpt/db/node_test.go
View file @
0b8360b0
...
@@ -21,9 +21,9 @@
...
@@ -21,9 +21,9 @@
package
mpt
package
mpt
import
(
import
(
"github.com/33cn/chain33/types"
"testing"
"testing"
proto
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
)
)
...
@@ -68,7 +68,6 @@ func TestCanUnload(t *testing.T) {
...
@@ -68,7 +68,6 @@ func TestCanUnload(t *testing.T) {
func
TestNodeProto
(
t
*
testing
.
T
)
{
func
TestNodeProto
(
t
*
testing
.
T
)
{
n
:=
&
Node
{
Value
:
&
Node_Full
{
Full
:
&
FullNode
{}}}
n
:=
&
Node
{
Value
:
&
Node_Full
{
Full
:
&
FullNode
{}}}
d
,
err
:=
proto
.
Marshal
(
n
)
d
:=
types
.
Encode
(
n
)
assert
.
Nil
(
t
,
nil
,
err
)
assert
.
Equal
(
t
,
2
,
len
(
d
))
assert
.
Equal
(
t
,
2
,
len
(
d
))
}
}
plugin/store/mpt/db/proof.go
View file @
0b8360b0
...
@@ -23,10 +23,10 @@ package mpt
...
@@ -23,10 +23,10 @@ package mpt
import
(
import
(
"bytes"
"bytes"
"fmt"
"fmt"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common"
dbm
"github.com/33cn/chain33/common/db"
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
// 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 {
...
@@ -79,7 +79,7 @@ func (t *Trie) Prove(key []byte, fromLevel uint, proofDb dbm.DB) error {
if
fromLevel
>
0
{
if
fromLevel
>
0
{
fromLevel
--
fromLevel
--
}
else
{
}
else
{
enc
,
_
:=
proto
.
Marshal
(
n
.
create
())
enc
:=
types
.
Encode
(
n
.
create
())
if
!
ok
{
if
!
ok
{
hash
=
createHashNode
(
common
.
Sha3
(
enc
))
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