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
e3397343
Commit
e3397343
authored
Apr 02, 2020
by
harrylee
Committed by
vipwzw
Apr 04, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add fork
parent
d34b1c84
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
176 additions
and
123 deletions
+176
-123
exec.go
plugin/dapp/storage/executor/exec.go
+1
-0
exec_local.go
plugin/dapp/storage/executor/exec_local.go
+60
-45
storage.go
plugin/dapp/storage/executor/storage.go
+5
-1
storage_test.go
plugin/dapp/storage/executor/storage_test.go
+5
-3
storagedb.go
plugin/dapp/storage/executor/storagedb.go
+101
-74
storage.go
plugin/dapp/storage/types/storage.go
+4
-0
No files found.
plugin/dapp/storage/executor/exec.go
View file @
e3397343
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
*/
*/
func
(
s
*
storage
)
Exec_ContentStorage
(
payload
*
storagetypes
.
ContentOnlyNotaryStorage
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
s
*
storage
)
Exec_ContentStorage
(
payload
*
storagetypes
.
ContentOnlyNotaryStorage
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
s
.
GetAPI
()
action
:=
newStorageAction
(
s
,
tx
,
index
)
action
:=
newStorageAction
(
s
,
tx
,
index
)
return
action
.
ContentStorage
(
payload
)
return
action
.
ContentStorage
(
payload
)
}
}
...
...
plugin/dapp/storage/executor/exec_local.go
View file @
e3397343
...
@@ -12,16 +12,19 @@ import (
...
@@ -12,16 +12,19 @@ import (
func
(
s
*
storage
)
ExecLocal_ContentStorage
(
payload
*
ety
.
ContentOnlyNotaryStorage
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
s
*
storage
)
ExecLocal_ContentStorage
(
payload
*
ety
.
ContentOnlyNotaryStorage
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
dbSet
:=
&
types
.
LocalDBSet
{}
dbSet
:=
&
types
.
LocalDBSet
{}
if
receiptData
.
Ty
==
types
.
ExecOk
{
cfg
:=
s
.
GetAPI
()
.
GetConfig
()
for
_
,
log
:=
range
receiptData
.
Logs
{
if
cfg
.
IsDappFork
(
s
.
GetHeight
(),
ety
.
StorageX
,
ety
.
ForkStorageLocalDB
)
{
switch
log
.
Ty
{
if
receiptData
.
Ty
==
types
.
ExecOk
{
case
ety
.
TyContentStorageLog
:
for
_
,
log
:=
range
receiptData
.
Logs
{
storage
:=
&
ety
.
Storage
{}
switch
log
.
Ty
{
if
err
:=
types
.
Decode
(
log
.
Log
,
storage
);
err
!=
nil
{
case
ety
.
TyContentStorageLog
:
return
nil
,
err
storage
:=
&
ety
.
Storage
{}
if
err
:=
types
.
Decode
(
log
.
Log
,
storage
);
err
!=
nil
{
return
nil
,
err
}
kv
:=
&
types
.
KeyValue
{
Key
:
getLocalDBKey
(
storage
.
GetContentStorage
()
.
Key
),
Value
:
types
.
Encode
(
storage
)}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kv
)
}
}
kv
:=
&
types
.
KeyValue
{
Key
:
getLocalDBKey
(
storage
.
GetContentStorage
()
.
Key
),
Value
:
types
.
Encode
(
storage
)}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kv
)
}
}
}
}
}
}
...
@@ -30,16 +33,19 @@ func (s *storage) ExecLocal_ContentStorage(payload *ety.ContentOnlyNotaryStorage
...
@@ -30,16 +33,19 @@ func (s *storage) ExecLocal_ContentStorage(payload *ety.ContentOnlyNotaryStorage
func
(
s
*
storage
)
ExecLocal_HashStorage
(
payload
*
ety
.
HashOnlyNotaryStorage
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
s
*
storage
)
ExecLocal_HashStorage
(
payload
*
ety
.
HashOnlyNotaryStorage
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
dbSet
:=
&
types
.
LocalDBSet
{}
dbSet
:=
&
types
.
LocalDBSet
{}
if
receiptData
.
Ty
==
types
.
ExecOk
{
cfg
:=
s
.
GetAPI
()
.
GetConfig
()
for
_
,
log
:=
range
receiptData
.
Logs
{
if
cfg
.
IsDappFork
(
s
.
GetHeight
(),
ety
.
StorageX
,
ety
.
ForkStorageLocalDB
)
{
switch
log
.
Ty
{
if
receiptData
.
Ty
==
types
.
ExecOk
{
case
ety
.
TyHashStorageLog
:
for
_
,
log
:=
range
receiptData
.
Logs
{
storage
:=
&
ety
.
Storage
{}
switch
log
.
Ty
{
if
err
:=
types
.
Decode
(
log
.
Log
,
storage
);
err
!=
nil
{
case
ety
.
TyHashStorageLog
:
return
nil
,
err
storage
:=
&
ety
.
Storage
{}
if
err
:=
types
.
Decode
(
log
.
Log
,
storage
);
err
!=
nil
{
return
nil
,
err
}
kv
:=
&
types
.
KeyValue
{
Key
:
getLocalDBKey
(
storage
.
GetHashStorage
()
.
Key
),
Value
:
types
.
Encode
(
storage
)}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kv
)
}
}
kv
:=
&
types
.
KeyValue
{
Key
:
getLocalDBKey
(
storage
.
GetHashStorage
()
.
Key
),
Value
:
types
.
Encode
(
storage
)}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kv
)
}
}
}
}
}
}
...
@@ -48,16 +54,19 @@ func (s *storage) ExecLocal_HashStorage(payload *ety.HashOnlyNotaryStorage, tx *
...
@@ -48,16 +54,19 @@ func (s *storage) ExecLocal_HashStorage(payload *ety.HashOnlyNotaryStorage, tx *
func
(
s
*
storage
)
ExecLocal_LinkStorage
(
payload
*
ety
.
LinkNotaryStorage
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
s
*
storage
)
ExecLocal_LinkStorage
(
payload
*
ety
.
LinkNotaryStorage
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
dbSet
:=
&
types
.
LocalDBSet
{}
dbSet
:=
&
types
.
LocalDBSet
{}
if
receiptData
.
Ty
==
types
.
ExecOk
{
cfg
:=
s
.
GetAPI
()
.
GetConfig
()
for
_
,
log
:=
range
receiptData
.
Logs
{
if
cfg
.
IsDappFork
(
s
.
GetHeight
(),
ety
.
StorageX
,
ety
.
ForkStorageLocalDB
)
{
switch
log
.
Ty
{
if
receiptData
.
Ty
==
types
.
ExecOk
{
case
ety
.
TyLinkStorageLog
:
for
_
,
log
:=
range
receiptData
.
Logs
{
storage
:=
&
ety
.
Storage
{}
switch
log
.
Ty
{
if
err
:=
types
.
Decode
(
log
.
Log
,
storage
);
err
!=
nil
{
case
ety
.
TyLinkStorageLog
:
return
nil
,
err
storage
:=
&
ety
.
Storage
{}
if
err
:=
types
.
Decode
(
log
.
Log
,
storage
);
err
!=
nil
{
return
nil
,
err
}
kv
:=
&
types
.
KeyValue
{
Key
:
getLocalDBKey
(
storage
.
GetLinkStorage
()
.
Key
),
Value
:
types
.
Encode
(
storage
)}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kv
)
}
}
kv
:=
&
types
.
KeyValue
{
Key
:
getLocalDBKey
(
storage
.
GetLinkStorage
()
.
Key
),
Value
:
types
.
Encode
(
storage
)}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kv
)
}
}
}
}
}
}
...
@@ -66,16 +75,19 @@ func (s *storage) ExecLocal_LinkStorage(payload *ety.LinkNotaryStorage, tx *type
...
@@ -66,16 +75,19 @@ func (s *storage) ExecLocal_LinkStorage(payload *ety.LinkNotaryStorage, tx *type
func
(
s
*
storage
)
ExecLocal_EncryptStorage
(
payload
*
ety
.
EncryptNotaryStorage
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
s
*
storage
)
ExecLocal_EncryptStorage
(
payload
*
ety
.
EncryptNotaryStorage
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
dbSet
:=
&
types
.
LocalDBSet
{}
dbSet
:=
&
types
.
LocalDBSet
{}
if
receiptData
.
Ty
==
types
.
ExecOk
{
cfg
:=
s
.
GetAPI
()
.
GetConfig
()
for
_
,
log
:=
range
receiptData
.
Logs
{
if
cfg
.
IsDappFork
(
s
.
GetHeight
(),
ety
.
StorageX
,
ety
.
ForkStorageLocalDB
)
{
switch
log
.
Ty
{
if
receiptData
.
Ty
==
types
.
ExecOk
{
case
ety
.
TyEncryptStorageLog
:
for
_
,
log
:=
range
receiptData
.
Logs
{
storage
:=
&
ety
.
Storage
{}
switch
log
.
Ty
{
if
err
:=
types
.
Decode
(
log
.
Log
,
storage
);
err
!=
nil
{
case
ety
.
TyEncryptStorageLog
:
return
nil
,
err
storage
:=
&
ety
.
Storage
{}
if
err
:=
types
.
Decode
(
log
.
Log
,
storage
);
err
!=
nil
{
return
nil
,
err
}
kv
:=
&
types
.
KeyValue
{
Key
:
getLocalDBKey
(
storage
.
GetEncryptStorage
()
.
Key
),
Value
:
types
.
Encode
(
storage
)}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kv
)
}
}
kv
:=
&
types
.
KeyValue
{
Key
:
getLocalDBKey
(
storage
.
GetEncryptStorage
()
.
Key
),
Value
:
types
.
Encode
(
storage
)}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kv
)
}
}
}
}
}
}
...
@@ -84,16 +96,19 @@ func (s *storage) ExecLocal_EncryptStorage(payload *ety.EncryptNotaryStorage, tx
...
@@ -84,16 +96,19 @@ func (s *storage) ExecLocal_EncryptStorage(payload *ety.EncryptNotaryStorage, tx
func
(
s
*
storage
)
ExecLocal_EncryptShareStorage
(
payload
*
ety
.
EncryptShareNotaryStorage
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
s
*
storage
)
ExecLocal_EncryptShareStorage
(
payload
*
ety
.
EncryptShareNotaryStorage
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
dbSet
:=
&
types
.
LocalDBSet
{}
dbSet
:=
&
types
.
LocalDBSet
{}
if
receiptData
.
Ty
==
types
.
ExecOk
{
cfg
:=
s
.
GetAPI
()
.
GetConfig
()
for
_
,
log
:=
range
receiptData
.
Logs
{
if
cfg
.
IsDappFork
(
s
.
GetHeight
(),
ety
.
StorageX
,
ety
.
ForkStorageLocalDB
)
{
switch
log
.
Ty
{
if
receiptData
.
Ty
==
types
.
ExecOk
{
case
ety
.
TyEncryptShareStorageLog
:
for
_
,
log
:=
range
receiptData
.
Logs
{
storage
:=
&
ety
.
Storage
{}
switch
log
.
Ty
{
if
err
:=
types
.
Decode
(
log
.
Log
,
storage
);
err
!=
nil
{
case
ety
.
TyEncryptShareStorageLog
:
return
nil
,
err
storage
:=
&
ety
.
Storage
{}
if
err
:=
types
.
Decode
(
log
.
Log
,
storage
);
err
!=
nil
{
return
nil
,
err
}
kv
:=
&
types
.
KeyValue
{
Key
:
getLocalDBKey
(
storage
.
GetEncryptShareStorage
()
.
Key
),
Value
:
types
.
Encode
(
storage
)}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kv
)
}
}
kv
:=
&
types
.
KeyValue
{
Key
:
getLocalDBKey
(
storage
.
GetEncryptShareStorage
()
.
Key
),
Value
:
types
.
Encode
(
storage
)}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kv
)
}
}
}
}
}
}
...
...
plugin/dapp/storage/executor/storage.go
View file @
e3397343
...
@@ -53,7 +53,11 @@ func (s *storage) GetDriverName() string {
...
@@ -53,7 +53,11 @@ func (s *storage) GetDriverName() string {
//ExecutorOrder Exec 的时候 同时执行 ExecLocal
//ExecutorOrder Exec 的时候 同时执行 ExecLocal
func
(
s
*
storage
)
ExecutorOrder
()
int64
{
func
(
s
*
storage
)
ExecutorOrder
()
int64
{
return
drivers
.
ExecLocalSameTime
cfg
:=
s
.
GetAPI
()
.
GetConfig
()
if
cfg
.
IsDappFork
(
s
.
GetHeight
(),
storagetypes
.
StorageX
,
storagetypes
.
ForkStorageLocalDB
)
{
return
drivers
.
ExecLocalSameTime
}
return
s
.
DriverBase
.
ExecutorOrder
()
}
}
// CheckTx 实现自定义检验交易接口,供框架调用
// CheckTx 实现自定义检验交易接口,供框架调用
...
...
plugin/dapp/storage/executor/storage_test.go
View file @
e3397343
...
@@ -4,6 +4,8 @@ import (
...
@@ -4,6 +4,8 @@ import (
"math/rand"
"math/rand"
"testing"
"testing"
"github.com/gogo/protobuf/proto"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/address"
...
@@ -64,6 +66,7 @@ func init() {
...
@@ -64,6 +66,7 @@ func init() {
func
TestStorage
(
t
*
testing
.
T
)
{
func
TestStorage
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
strings
.
Replace
(
types
.
GetDefaultCfgstring
(),
"Title=
\"
local
\"
"
,
"Title=
\"
chain33
\"
"
,
1
))
cfg
:=
types
.
NewChain33Config
(
strings
.
Replace
(
types
.
GetDefaultCfgstring
(),
"Title=
\"
local
\"
"
,
"Title=
\"
chain33
\"
"
,
1
))
Init
(
oty
.
StorageX
,
cfg
,
nil
)
Init
(
oty
.
StorageX
,
cfg
,
nil
)
cfg
.
RegisterDappFork
(
oty
.
StorageX
,
oty
.
ForkStorageLocalDB
,
0
)
total
:=
100
*
types
.
Coin
total
:=
100
*
types
.
Coin
accountA
:=
types
.
Account
{
accountA
:=
types
.
Account
{
Balance
:
total
,
Balance
:
total
,
...
@@ -162,7 +165,6 @@ func TestStorage(t *testing.T) {
...
@@ -162,7 +165,6 @@ func TestStorage(t *testing.T) {
assert
.
Equal
(
t
,
common
.
Sha256
(
contents
[
0
]),
reply
.
GetEncryptStorage
()
.
ContentHash
)
assert
.
Equal
(
t
,
common
.
Sha256
(
contents
[
0
]),
reply
.
GetEncryptStorage
()
.
ContentHash
)
assert
.
Equal
(
t
,
crypted
,
reply
.
GetEncryptStorage
()
.
EncryptContent
)
assert
.
Equal
(
t
,
crypted
,
reply
.
GetEncryptStorage
()
.
EncryptContent
)
assert
.
Equal
(
t
,
ivs
[
0
],
reply
.
GetEncryptStorage
()
.
Nonce
)
assert
.
Equal
(
t
,
ivs
[
0
],
reply
.
GetEncryptStorage
()
.
Nonce
)
}
}
func
signTx
(
tx
*
types
.
Transaction
,
hexPrivKey
string
)
(
*
types
.
Transaction
,
error
)
{
func
signTx
(
tx
*
types
.
Transaction
,
hexPrivKey
string
)
(
*
types
.
Transaction
,
error
)
{
...
@@ -201,7 +203,7 @@ func QueryStorageByKey(stateDB dbm.KV, kvdb dbm.KVDB, key string, cfg *types.Cha
...
@@ -201,7 +203,7 @@ func QueryStorageByKey(stateDB dbm.KV, kvdb dbm.KVDB, key string, cfg *types.Cha
}
}
return
msg
.
(
*
oty
.
Storage
),
nil
return
msg
.
(
*
oty
.
Storage
),
nil
}
}
func
QueryBatchStorageByKey
(
stateDB
dbm
.
KV
,
kvdb
dbm
.
KVDB
,
para
*
oty
.
BatchQueryStor
age
,
cfg
*
types
.
Chain33Config
)
(
*
oty
.
BatchReplyStorage
,
error
)
{
func
QueryBatchStorageByKey
(
stateDB
dbm
.
KV
,
kvdb
dbm
.
KVDB
,
para
proto
.
Mess
age
,
cfg
*
types
.
Chain33Config
)
(
*
oty
.
BatchReplyStorage
,
error
)
{
exec
:=
newStorage
()
exec
:=
newStorage
()
q
:=
queue
.
New
(
"channel"
)
q
:=
queue
.
New
(
"channel"
)
q
.
SetConfig
(
cfg
)
q
.
SetConfig
(
cfg
)
...
@@ -233,6 +235,7 @@ func CreateTx(action string, message types.Message, priv string, cfg *types.Chai
...
@@ -233,6 +235,7 @@ func CreateTx(action string, message types.Message, priv string, cfg *types.Chai
//模拟区块中交易得执行过程
//模拟区块中交易得执行过程
func
Exec_Block
(
t
*
testing
.
T
,
stateDB
dbm
.
DB
,
kvdb
dbm
.
KVDB
,
env
*
execEnv
,
txs
...*
types
.
Transaction
)
error
{
func
Exec_Block
(
t
*
testing
.
T
,
stateDB
dbm
.
DB
,
kvdb
dbm
.
KVDB
,
env
*
execEnv
,
txs
...*
types
.
Transaction
)
error
{
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
cfg
.
RegisterDappFork
(
oty
.
StorageX
,
oty
.
ForkStorageLocalDB
,
0
)
cfg
.
SetTitleOnlyForTest
(
"chain33"
)
cfg
.
SetTitleOnlyForTest
(
"chain33"
)
exec
:=
newStorage
()
exec
:=
newStorage
()
e
:=
exec
.
(
*
storage
)
e
:=
exec
.
(
*
storage
)
...
@@ -242,7 +245,6 @@ func Exec_Block(t *testing.T, stateDB dbm.DB, kvdb dbm.KVDB, env *execEnv, txs .
...
@@ -242,7 +245,6 @@ func Exec_Block(t *testing.T, stateDB dbm.DB, kvdb dbm.KVDB, env *execEnv, txs .
t
.
Log
(
err
.
Error
())
t
.
Log
(
err
.
Error
())
return
err
return
err
}
}
}
}
q
:=
queue
.
New
(
"channel"
)
q
:=
queue
.
New
(
"channel"
)
q
.
SetConfig
(
cfg
)
q
.
SetConfig
(
cfg
)
...
...
plugin/dapp/storage/executor/storagedb.go
View file @
e3397343
...
@@ -2,7 +2,7 @@ package executor
...
@@ -2,7 +2,7 @@ package executor
import
(
import
(
"fmt"
"fmt"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common"
dbm
"github.com/33cn/chain33/common/db"
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
)
)
type
StorageAction
struct
{
type
StorageAction
struct
{
api
client
.
QueueProtocolAPI
db
dbm
.
KV
db
dbm
.
KV
localdb
dbm
.
KV
localdb
dbm
.
KV
txhash
[]
byte
txhash
[]
byte
...
@@ -23,7 +24,7 @@ type StorageAction struct {
...
@@ -23,7 +24,7 @@ type StorageAction struct {
func
newStorageAction
(
s
*
storage
,
tx
*
types
.
Transaction
,
index
int
)
*
StorageAction
{
func
newStorageAction
(
s
*
storage
,
tx
*
types
.
Transaction
,
index
int
)
*
StorageAction
{
hash
:=
tx
.
Hash
()
hash
:=
tx
.
Hash
()
fromaddr
:=
tx
.
From
()
fromaddr
:=
tx
.
From
()
return
&
StorageAction
{
s
.
GetStateDB
(),
s
.
GetLocalDB
(),
hash
,
fromaddr
,
return
&
StorageAction
{
s
.
Get
API
(),
s
.
Get
StateDB
(),
s
.
GetLocalDB
(),
hash
,
fromaddr
,
s
.
GetBlockTime
(),
s
.
GetHeight
(),
index
}
s
.
GetBlockTime
(),
s
.
GetHeight
(),
index
}
}
}
func
(
s
*
StorageAction
)
GetKVSet
(
payload
proto
.
Message
)
(
kvset
[]
*
types
.
KeyValue
)
{
func
(
s
*
StorageAction
)
GetKVSet
(
payload
proto
.
Message
)
(
kvset
[]
*
types
.
KeyValue
)
{
...
@@ -36,99 +37,135 @@ func (s *StorageAction) ContentStorage(payload *ety.ContentOnlyNotaryStorage) (*
...
@@ -36,99 +37,135 @@ func (s *StorageAction) ContentStorage(payload *ety.ContentOnlyNotaryStorage) (*
//TODO 这里可以加具体得文本内容限制,超过指定大小的数据不容许写到状态数据库中
//TODO 这里可以加具体得文本内容限制,超过指定大小的数据不容许写到状态数据库中
var
logs
[]
*
types
.
ReceiptLog
var
logs
[]
*
types
.
ReceiptLog
var
kvs
[]
*
types
.
KeyValue
var
kvs
[]
*
types
.
KeyValue
key
:=
payload
.
Key
cfg
:=
s
.
api
.
GetConfig
()
op
:=
payload
.
Op
if
cfg
.
IsDappFork
(
s
.
height
,
ety
.
StorageX
,
ety
.
ForkStorageLocalDB
)
{
if
key
==
""
{
key
:=
payload
.
Key
key
=
common
.
ToHex
(
s
.
txhash
)
op
:=
payload
.
Op
}
if
key
==
""
{
payload
.
Key
=
key
key
=
common
.
ToHex
(
s
.
txhash
)
storage
,
err
:=
QueryStorageFromLocalDB
(
s
.
localdb
,
key
)
if
op
==
ety
.
OpCreate
{
if
err
!=
types
.
ErrNotFound
{
return
nil
,
ety
.
ErrKeyExisted
}
}
}
else
{
payload
.
Key
=
key
if
err
==
nil
&&
storage
.
Ty
!=
ety
.
TyContentStorageAction
{
storage
,
err
:=
QueryStorageFromLocalDB
(
s
.
localdb
,
key
)
return
nil
,
ety
.
ErrStorageType
if
op
==
ety
.
OpCreate
{
if
err
!=
types
.
ErrNotFound
{
return
nil
,
ety
.
ErrKeyExisted
}
}
else
{
if
err
==
nil
&&
storage
.
Ty
!=
ety
.
TyContentStorageAction
{
return
nil
,
ety
.
ErrStorageType
}
content
:=
append
(
storage
.
GetContentStorage
()
.
Content
,
[]
byte
(
","
)
...
)
payload
.
Content
=
append
(
content
,
payload
.
Content
...
)
}
}
content
:=
append
(
storage
.
GetContentStorage
()
.
Content
,
[]
byte
(
","
)
...
)
stg
:=
&
ety
.
Storage
{
Value
:
&
ety
.
Storage_ContentStorage
{
ContentStorage
:
payload
},
Ty
:
ety
.
TyContentStorageAction
}
payload
.
Content
=
append
(
content
,
payload
.
Content
...
)
log
:=
&
types
.
ReceiptLog
{
Ty
:
ety
.
TyContentStorageLog
,
Log
:
types
.
Encode
(
stg
)}
logs
=
append
(
logs
,
log
)
}
else
{
log
:=
&
types
.
ReceiptLog
{
Ty
:
ety
.
TyContentStorageLog
}
logs
=
append
(
logs
,
log
)
kvs
=
s
.
GetKVSet
(
&
ety
.
Storage
{
Value
:
&
ety
.
Storage_ContentStorage
{
ContentStorage
:
payload
}})
}
}
stg
:=
&
ety
.
Storage
{
Value
:
&
ety
.
Storage_ContentStorage
{
ContentStorage
:
payload
},
Ty
:
ety
.
TyContentStorageAction
}
log
:=
&
types
.
ReceiptLog
{
Ty
:
ety
.
TyContentStorageLog
,
Log
:
types
.
Encode
(
stg
)}
logs
=
append
(
logs
,
log
)
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kvs
,
Logs
:
logs
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kvs
,
Logs
:
logs
}
return
receipt
,
nil
return
receipt
,
nil
}
}
func
(
s
*
StorageAction
)
HashStorage
(
payload
*
ety
.
HashOnlyNotaryStorage
)
(
*
types
.
Receipt
,
error
)
{
func
(
s
*
StorageAction
)
HashStorage
(
payload
*
ety
.
HashOnlyNotaryStorage
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
logs
[]
*
types
.
ReceiptLog
var
kvs
[]
*
types
.
KeyValue
var
kvs
[]
*
types
.
KeyValue
key
:=
payload
.
Key
cfg
:=
s
.
api
.
GetConfig
()
if
key
==
""
{
if
cfg
.
IsDappFork
(
s
.
height
,
ety
.
StorageX
,
ety
.
ForkStorageLocalDB
)
{
key
=
common
.
ToHex
(
s
.
txhash
)
key
:=
payload
.
Key
}
if
key
==
""
{
_
,
err
:=
QueryStorageFromLocalDB
(
s
.
localdb
,
key
)
key
=
common
.
ToHex
(
s
.
txhash
)
if
err
!=
types
.
ErrNotFound
{
}
return
nil
,
ety
.
ErrKeyExisted
_
,
err
:=
QueryStorageFromLocalDB
(
s
.
localdb
,
key
)
if
err
!=
types
.
ErrNotFound
{
return
nil
,
ety
.
ErrKeyExisted
}
payload
.
Key
=
key
stg
:=
&
ety
.
Storage
{
Value
:
&
ety
.
Storage_HashStorage
{
HashStorage
:
payload
},
Ty
:
ety
.
TyHashStorageAction
}
log
:=
&
types
.
ReceiptLog
{
Ty
:
ety
.
TyHashStorageLog
,
Log
:
types
.
Encode
(
stg
)}
logs
=
append
(
logs
,
log
)
}
else
{
log
:=
&
types
.
ReceiptLog
{
Ty
:
ety
.
TyHashStorageLog
}
logs
=
append
(
logs
,
log
)
kvs
=
s
.
GetKVSet
(
&
ety
.
Storage
{
Value
:
&
ety
.
Storage_HashStorage
{
HashStorage
:
payload
}})
}
}
payload
.
Key
=
key
stg
:=
&
ety
.
Storage
{
Value
:
&
ety
.
Storage_HashStorage
{
HashStorage
:
payload
},
Ty
:
ety
.
TyHashStorageAction
}
log
:=
&
types
.
ReceiptLog
{
Ty
:
ety
.
TyHashStorageLog
,
Log
:
types
.
Encode
(
stg
)}
logs
=
append
(
logs
,
log
)
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kvs
,
Logs
:
logs
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kvs
,
Logs
:
logs
}
return
receipt
,
nil
return
receipt
,
nil
}
}
func
(
s
*
StorageAction
)
LinkStorage
(
payload
*
ety
.
LinkNotaryStorage
)
(
*
types
.
Receipt
,
error
)
{
func
(
s
*
StorageAction
)
LinkStorage
(
payload
*
ety
.
LinkNotaryStorage
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
logs
[]
*
types
.
ReceiptLog
var
kvs
[]
*
types
.
KeyValue
var
kvs
[]
*
types
.
KeyValue
key
:=
payload
.
Key
cfg
:=
s
.
api
.
GetConfig
()
if
key
==
""
{
if
cfg
.
IsDappFork
(
s
.
height
,
ety
.
StorageX
,
ety
.
ForkStorageLocalDB
)
{
key
=
common
.
ToHex
(
s
.
txhash
)
key
:=
payload
.
Key
}
if
key
==
""
{
payload
.
Key
=
key
key
=
common
.
ToHex
(
s
.
txhash
)
_
,
err
:=
QueryStorageFromLocalDB
(
s
.
localdb
,
key
)
}
if
err
!=
types
.
ErrNotFound
{
payload
.
Key
=
key
return
nil
,
ety
.
ErrKeyExisted
_
,
err
:=
QueryStorageFromLocalDB
(
s
.
localdb
,
key
)
if
err
!=
types
.
ErrNotFound
{
return
nil
,
ety
.
ErrKeyExisted
}
stg
:=
&
ety
.
Storage
{
Value
:
&
ety
.
Storage_LinkStorage
{
LinkStorage
:
payload
},
Ty
:
ety
.
TyLinkStorageAction
}
log
:=
&
types
.
ReceiptLog
{
Ty
:
ety
.
TyLinkStorageLog
,
Log
:
types
.
Encode
(
stg
)}
logs
=
append
(
logs
,
log
)
}
else
{
log
:=
&
types
.
ReceiptLog
{
Ty
:
ety
.
TyLinkStorageLog
}
logs
=
append
(
logs
,
log
)
kvs
=
s
.
GetKVSet
(
&
ety
.
Storage
{
Value
:
&
ety
.
Storage_LinkStorage
{
LinkStorage
:
payload
}})
}
}
stg
:=
&
ety
.
Storage
{
Value
:
&
ety
.
Storage_LinkStorage
{
LinkStorage
:
payload
},
Ty
:
ety
.
TyLinkStorageAction
}
log
:=
&
types
.
ReceiptLog
{
Ty
:
ety
.
TyLinkStorageLog
,
Log
:
types
.
Encode
(
stg
)}
logs
=
append
(
logs
,
log
)
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kvs
,
Logs
:
logs
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kvs
,
Logs
:
logs
}
return
receipt
,
nil
return
receipt
,
nil
}
}
func
(
s
*
StorageAction
)
EncryptStorage
(
payload
*
ety
.
EncryptNotaryStorage
)
(
*
types
.
Receipt
,
error
)
{
func
(
s
*
StorageAction
)
EncryptStorage
(
payload
*
ety
.
EncryptNotaryStorage
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
logs
[]
*
types
.
ReceiptLog
var
kvs
[]
*
types
.
KeyValue
var
kvs
[]
*
types
.
KeyValue
key
:=
payload
.
Key
cfg
:=
s
.
api
.
GetConfig
()
if
key
==
""
{
if
cfg
.
IsDappFork
(
s
.
height
,
ety
.
StorageX
,
ety
.
ForkStorageLocalDB
)
{
key
=
common
.
ToHex
(
s
.
txhash
)
key
:=
payload
.
Key
}
if
key
==
""
{
payload
.
Key
=
key
key
=
common
.
ToHex
(
s
.
txhash
)
_
,
err
:=
QueryStorageFromLocalDB
(
s
.
localdb
,
key
)
}
if
err
!=
types
.
ErrNotFound
{
payload
.
Key
=
key
return
nil
,
ety
.
ErrKeyExisted
_
,
err
:=
QueryStorageFromLocalDB
(
s
.
localdb
,
key
)
if
err
!=
types
.
ErrNotFound
{
return
nil
,
ety
.
ErrKeyExisted
}
stg
:=
&
ety
.
Storage
{
Value
:
&
ety
.
Storage_EncryptStorage
{
EncryptStorage
:
payload
},
Ty
:
ety
.
TyEncryptStorageAction
}
log
:=
&
types
.
ReceiptLog
{
Ty
:
ety
.
TyEncryptStorageLog
,
Log
:
types
.
Encode
(
stg
)}
logs
=
append
(
logs
,
log
)
}
else
{
log
:=
&
types
.
ReceiptLog
{
Ty
:
ety
.
TyEncryptStorageLog
}
logs
=
append
(
logs
,
log
)
kvs
=
s
.
GetKVSet
(
&
ety
.
Storage
{
Value
:
&
ety
.
Storage_EncryptStorage
{
EncryptStorage
:
payload
}})
}
}
stg
:=
&
ety
.
Storage
{
Value
:
&
ety
.
Storage_EncryptStorage
{
EncryptStorage
:
payload
},
Ty
:
ety
.
TyEncryptStorageAction
}
log
:=
&
types
.
ReceiptLog
{
Ty
:
ety
.
TyEncryptStorageLog
,
Log
:
types
.
Encode
(
stg
)}
logs
=
append
(
logs
,
log
)
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kvs
,
Logs
:
logs
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kvs
,
Logs
:
logs
}
return
receipt
,
nil
return
receipt
,
nil
}
}
func
(
s
*
StorageAction
)
EncryptShareStorage
(
payload
*
ety
.
EncryptShareNotaryStorage
)
(
*
types
.
Receipt
,
error
)
{
func
(
s
*
StorageAction
)
EncryptShareStorage
(
payload
*
ety
.
EncryptShareNotaryStorage
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
logs
[]
*
types
.
ReceiptLog
var
kvs
[]
*
types
.
KeyValue
var
kvs
[]
*
types
.
KeyValue
key
:=
payload
.
Key
cfg
:=
s
.
api
.
GetConfig
()
if
key
==
""
{
if
cfg
.
IsDappFork
(
s
.
height
,
ety
.
StorageX
,
ety
.
ForkStorageLocalDB
)
{
key
=
common
.
ToHex
(
s
.
txhash
)
key
:=
payload
.
Key
}
if
key
==
""
{
payload
.
Key
=
key
key
=
common
.
ToHex
(
s
.
txhash
)
_
,
err
:=
QueryStorageFromLocalDB
(
s
.
localdb
,
key
)
}
if
err
!=
types
.
ErrNotFound
{
payload
.
Key
=
key
return
nil
,
ety
.
ErrKeyExisted
_
,
err
:=
QueryStorageFromLocalDB
(
s
.
localdb
,
key
)
if
err
!=
types
.
ErrNotFound
{
return
nil
,
ety
.
ErrKeyExisted
}
stg
:=
&
ety
.
Storage
{
Value
:
&
ety
.
Storage_EncryptShareStorage
{
EncryptShareStorage
:
payload
},
Ty
:
ety
.
TyEncryptStorageAction
}
log
:=
&
types
.
ReceiptLog
{
Ty
:
ety
.
TyEncryptShareStorageLog
,
Log
:
types
.
Encode
(
stg
)}
logs
=
append
(
logs
,
log
)
}
else
{
log
:=
&
types
.
ReceiptLog
{
Ty
:
ety
.
TyEncryptShareStorageLog
}
logs
=
append
(
logs
,
log
)
kvs
=
s
.
GetKVSet
(
&
ety
.
Storage
{
Value
:
&
ety
.
Storage_EncryptShareStorage
{
EncryptShareStorage
:
payload
}})
}
}
stg
:=
&
ety
.
Storage
{
Value
:
&
ety
.
Storage_EncryptShareStorage
{
EncryptShareStorage
:
payload
},
Ty
:
ety
.
TyEncryptStorageAction
}
log
:=
&
types
.
ReceiptLog
{
Ty
:
ety
.
TyEncryptShareStorageLog
,
Log
:
types
.
Encode
(
stg
)}
logs
=
append
(
logs
,
log
)
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kvs
,
Logs
:
logs
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kvs
,
Logs
:
logs
}
return
receipt
,
nil
return
receipt
,
nil
}
}
...
@@ -186,13 +223,3 @@ func QueryStorageFromLocalDB(localdb dbm.KV, key string) (*ety.Storage, error) {
...
@@ -186,13 +223,3 @@ func QueryStorageFromLocalDB(localdb dbm.KV, key string) (*ety.Storage, error) {
}
}
return
&
storage
,
nil
return
&
storage
,
nil
}
}
//func QueryStorageFromLocalDB(localdb dbm.KV, key string) (*ety.Storage, error) {
// storageTable := NewStorageTable(localdb)
// row, err := storageTable.GetData([]byte(key))
// if err != nil {
// return nil, err
// }
// fmt.Println(row)
// return row.Data.(*ety.Storage), nil
//}
plugin/dapp/storage/types/storage.go
View file @
e3397343
...
@@ -47,6 +47,9 @@ const (
...
@@ -47,6 +47,9 @@ const (
)
)
var
(
var
(
ForkStorageLocalDB
=
"ForkStorageLocalDB"
)
var
(
//StorageX 执行器名称定义
//StorageX 执行器名称定义
StorageX
=
"storage"
StorageX
=
"storage"
//定义actionMap
//定义actionMap
...
@@ -78,6 +81,7 @@ func init() {
...
@@ -78,6 +81,7 @@ func init() {
// InitFork defines register fork
// InitFork defines register fork
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
StorageX
,
"Enable"
,
0
)
cfg
.
RegisterDappFork
(
StorageX
,
"Enable"
,
0
)
cfg
.
RegisterDappFork
(
StorageX
,
ForkStorageLocalDB
,
0
)
}
}
// InitExecutor defines register executor
// InitExecutor defines register executor
...
...
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