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
bbbba0f1
Commit
bbbba0f1
authored
May 24, 2019
by
pengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add retrieve rpc-test
parent
bf75f36f
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
381 additions
and
48 deletions
+381
-48
test-rpc.sh
plugin/dapp/pokerbull/cmd/build/test-rpc.sh
+122
-45
Makefile
plugin/dapp/retrieve/cmd/Makefile
+4
-0
build.sh
plugin/dapp/retrieve/cmd/build.sh
+15
-0
test-rpc.sh
plugin/dapp/retrieve/cmd/build/test-rpc.sh
+237
-0
retrieve.go
plugin/dapp/retrieve/cmd/retrieve.go
+1
-1
plugin.go
plugin/dapp/retrieve/plugin.go
+2
-2
No files found.
plugin/dapp/pokerbull/cmd/build/test-rpc.sh
View file @
bbbba0f1
...
@@ -5,10 +5,7 @@ set -o pipefail
...
@@ -5,10 +5,7 @@ set -o pipefail
MAIN_HTTP
=
""
MAIN_HTTP
=
""
CASE_ERR
=
""
CASE_ERR
=
""
START_TX
=
""
GAME_ID
=
""
CONTINUE_TX
=
""
QUIT_TX
=
""
PLAY_TX
=
""
#color
#color
RED
=
'\033[1;31m'
RED
=
'\033[1;31m'
...
@@ -16,7 +13,7 @@ GRE='\033[1;32m'
...
@@ -16,7 +13,7 @@ GRE='\033[1;32m'
NOC
=
'\033[0m'
NOC
=
'\033[0m'
echo_rst
()
{
echo_rst
()
{
if
[
"
$2
"
==
true
]
;
then
if
[
"
$2
"
==
0
]
;
then
echo
-e
"
${
GRE
}
$1
ok
${
NOC
}
"
echo
-e
"
${
GRE
}
$1
ok
${
NOC
}
"
else
else
echo
-e
"
${
RED
}
$1
fail
${
NOC
}
"
echo
-e
"
${
RED
}
$1
fail
${
NOC
}
"
...
@@ -25,74 +22,156 @@ echo_rst() {
...
@@ -25,74 +22,156 @@ echo_rst() {
}
}
function
block_wait
()
{
local
req
=
'"method":"Chain33.GetLastHeader","params":[]'
cur_height
=
$(
curl
-ksd
"{
$req
}"
${
MAIN_HTTP
}
| jq
".result.height"
)
expect
=
$((
cur_height
+
${
1
}))
local
count
=
0
while
true
;
do
new_height
=
$(
curl
-ksd
"{
$req
}"
${
MAIN_HTTP
}
| jq
".result.height"
)
if
[
"
${
new_height
}
"
-ge
"
${
expect
}
"
]
;
then
break
fi
count
=
$((
count
+
1
))
sleep
1
done
echo
"wait new block
$count
s, cur height=
$expect
,old=
$cur_height
"
}
function
query_tx
()
{
block_wait 1
local
txhash
=
"
$1
"
local
req
=
'"method":"Chain33.QueryTransaction","params":[{"hash":"'
"
$txhash
"
'"}]'
# echo "req=$req"
local times
=
10
while
true
;
do
ret
=
$(
curl
-ksd
"{
$req
}"
${
MAIN_HTTP
}
| jq
-r
".result.tx.hash"
)
echo
"====query tx=
${
1
}
, return=
$ret
"
if
[
"
${
ret
}
"
!=
"
${
1
}
"
]
;
then
block_wait 1
times
=
$((
times
-
1
))
if
[
$times
-le
0
]
;
then
echo
"====query tx=
$1
failed"
echo
"req=
$req
"
curl
-ksd
"{
$req
}"
${
MAIN_HTTP
}
exit
1
fi
else
echo
"====query tx=
$1
success"
break
fi
done
}
pokerbull_PlayRawTx
()
{
pokerbull_PlayRawTx
()
{
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Play","payload":{"gameI
D":"'
$START_TX
'
", "value":"1000000000", "round":1}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Play","payload":{"gameI
d":"pokerbull-abc
", "value":"1000000000", "round":1}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
PLAY_TX
=
$tx
PLAY_TX
=
$tx
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer == "
Play
")'
<<<
"
$data
"
)
ok
=
$(
jq
'(.execer == "
pokerbull
")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
[
"
$ok
"
==
true
]
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$?
"
echo_rst
"
$FUNCNAME
"
"
$rst
"
signrawtx
"
$tx
"
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
"play"
}
}
pokerbull_QuitRawTx
()
{
pokerbull_QuitRawTx
()
{
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Quit","payload":{"gameI
D":"'
$START_TX
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Quit","payload":{"gameI
d":"'
$GAME_ID
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
QUIT_TX
=
$tx
QUIT_TX
=
$tx
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer == "
Quit
")'
<<<
"
$data
"
)
ok
=
$(
jq
'(.execer == "
pokerbull
")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
[
"
$ok
"
==
true
]
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$?
"
echo_rst
"
$FUNCNAME
"
"
$rst
"
signrawtx
"
$tx
"
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
"quit"
}
}
pokerbull_ContinueRawTx
()
{
pokerbull_ContinueRawTx
()
{
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Continue","payload":{"gameI
D":"'
$START_TX
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Continue","payload":{"gameI
d":"'
$GAME_ID
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
CONTINUE_TX
=
$tx
CONTINUE_TX
=
$tx
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer == "
Continue
")'
<<<
"
$data
"
)
ok
=
$(
jq
'(.execer == "
pokerbull
")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
[
"
$ok
"
==
true
]
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$?
"
echo_rst
"
$FUNCNAME
"
"
$rst
"
signrawtx
"
$tx
"
"0x9c451df9e5cb05b88b28729aeaaeb3169a2414097401fcb4c79c1971df734588"
"continue"
}
}
pokerbull_StartRawTx
()
{
pokerbull_StartRawTx
()
{
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Start","payload":{"value":"1000000000", "playerNum":"2"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Start","payload":{"value":"1000000000", "playerNum":"2"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
START_TX
=
$tx
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer == "
Start
")'
<<<
"
$data
"
)
ok
=
$(
jq
'(.execer == "
pokerbull
")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
[
"
$ok
"
==
true
]
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$?
"
echo_rst
"
$FUNCNAME
"
"
$rst
"
}
Chain33_SendRawTx
()
{
signrawtx
"
$tx
"
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
"start"
local
req
=
'"method":"Chain33.SignRawTx", "params":[{"data":"'
"
$1
"
'", "addr":"'
"
$2
"
'", "expire":"3600"}]'
}
# echo "#request: $req"
pokerbull_QueryResult
()
{
resp
=
$(
curl
-ksd
"{
$req
}"
"
${
MAIN_HTTP
}
"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByID","payload":{"gameId":"'
$GAME_ID
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
ok
=
$(
jq
'(.game.gameId == "'
$GAME_ID
'")'
<<<
"
$data
"
)
# echo "#response: $resp"
ok
=
$(
jq
'(.error|not)'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
echo_rst
"
$FUNCNAME
"
"
$?
"
local
reqSend
=
'"method":"Chain33.SendTransaction", "params":[{"data":"'
"
$resp
"
'"}]'
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByAddr","payload":{"addr":"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
echo_rst
"
$FUNCNAME
"
"
$?
"
# echo "#request: $req"
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByStatus","payload":{"status":"3"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
respSend
=
$(
curl
-ksd
"{
$req
}"
"
${
MAIN_HTTP
}
"
)
[
"
$data
"
!=
null
]
echo_rst
"
$FUNCNAME
"
"
$?
"
}
# echo "#response: $resp"
chain33_ImportPrivkey
()
{
okSend
=
$(
jq
'(.error|not)'
<<<
"
$respSend
"
)
local
pri
=
$2
[
"
$okSend
"
==
true
]
local
acc
=
$3
local
req
=
'"method":"Chain33.ImportPrivkey", "params":[{"privkey":"'
"
$pri
"
'", "label":"pokerbullimportkey1"}]'
echo
"#request:
$req
"
resp
=
$(
curl
-ksd
"{
$req
}"
"
$1
"
)
echo
"#response:
$resp
"
ok
=
$(
jq
'(.error|not) and (.result.label=="pokerbullimportkey1") and (.result.acc.addr == "'
"
$acc
"
'")'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
echo_rst
"
$FUNCNAME
"
"
$?
"
}
signrawtx
()
{
txHex
=
"
$1
"
priKey
=
"
$2
"
type
=
"
$3
"
local
req
=
'"method":"Chain33.SignRawTx","params":[{"privkey":"'
"
$priKey
"
'","txHex":"'
"
$txHex
"
'","expire":"120s"}]'
signedTx
=
$(
curl
-ksd
"{
$req
}"
${
MAIN_HTTP
}
| jq
-r
".result"
)
if
[
"
$signedTx
"
!=
null
]
;
then
sendTx
"
$signedTx
"
"
$3
"
else
echo
"signedTx null error"
fi
}
sendTx
()
{
signedTx
=
$1
type
=
$2
local
req
=
'"method":"Chain33.SendTransaction","params":[{"token":"BTY","data":"'
"
$signedTx
"
'"}]'
resp
=
$(
curl
-ksd
"{
$req
}"
${
MAIN_HTTP
})
err
=
$(
jq
'(.error)'
<<<
"
$resp
"
)
txhash
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
if
[
"
$err
"
==
null
]
;
then
query_tx
"
$txhash
"
if
[
"
$type
"
==
"start"
]
;
then
GAME_ID
=
$txhash
fi
else
echo
"send tx error:
$err
"
fi
}
}
Chain33_SendToAddress
()
{
Chain33_SendToAddress
()
{
...
@@ -100,30 +179,25 @@ Chain33_SendToAddress() {
...
@@ -100,30 +179,25 @@ Chain33_SendToAddress() {
local
to
=
"
$2
"
local
to
=
"
$2
"
local
amount
=
$3
local
amount
=
$3
local
req
=
'"method":"Chain33.SendToAddress", "params":[{"from":"'
"
$from
"
'","to":"'
"
$to
"
'", "amount":'
"
$amount
"
', "note":"test\n"}]'
local
req
=
'"method":"Chain33.SendToAddress", "params":[{"from":"'
"
$from
"
'","to":"'
"
$to
"
'", "amount":'
"
$amount
"
', "note":"test\n"}]'
# echo "#request: $req"
resp
=
$(
curl
-ksd
"{
$req
}"
"
${
MAIN_HTTP
}
"
)
resp
=
$(
curl
-ksd
"{
$req
}"
"
${
MAIN_HTTP
}
"
)
# echo "#response: $resp"
ok
=
$(
jq
'(.error|not) and (.result.hash|length==66)'
<<<
"
$resp
"
)
ok
=
$(
jq
'(.error|not) and (.result.hash|length==66)'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
echo_rst
"
$FUNCNAME
"
"
$?
"
hash
=
$(
jq
'(.result.hash)'
<<<
"
$resp
"
)
hash
=
$(
jq
'(.result.hash)'
<<<
"
$resp
"
)
echo
"hash=
$hash
"
echo
"hash=
$hash
"
# query_tx "$hash"
}
}
init
()
{
init
()
{
ispara
=
$(
echo
'"'
"
${
MAIN_HTTP
}
"
'"'
| jq
'.|contains("8901")'
)
ispara
=
$(
echo
'"'
"
${
MAIN_HTTP
}
"
'"'
| jq
'.|contains("8901")'
)
echo
"ipara=
$ispara
"
echo
"ipara=
$ispara
"
local
relay_addr
=
""
if
[
"
$ispara
"
==
true
]
;
then
if
[
"
$ispara
"
==
true
]
;
then
pokerbull_addr
=
$(
curl
-ksd
'{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.pokerbull"}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
pokerbull_addr
=
$(
curl
-ksd
'{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.pokerbull"}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
else
else
chain33_ImportPrivkey
"
${
MAIN_HTTP
}
"
"0x9c451df9e5cb05b88b28729aeaaeb3169a2414097401fcb4c79c1971df734588"
"1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY"
pokerbull_addr
=
$(
curl
-ksd
'{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"pokerbull"}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
pokerbull_addr
=
$(
curl
-ksd
'{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"pokerbull"}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
fi
fi
echo
"pokerbulladdr=
$pokerbull_addr
"
echo
"pokerbulladdr=
$pokerbull_addr
"
from
=
"1
2qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
"
from
=
"1
4KEKbYtKKQm4wMthSK9J4La4nAiidGozt
"
Chain33_SendToAddress
"
$from
"
"
$pokerbull_addr
"
10000000000
Chain33_SendToAddress
"
$from
"
"
$pokerbull_addr
"
10000000000
from
=
"1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY"
from
=
"1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY"
...
@@ -133,11 +207,14 @@ init() {
...
@@ -133,11 +207,14 @@ init() {
function
run_test
()
{
function
run_test
()
{
pokerbull_StartRawTx
pokerbull_StartRawTx
Chain33_SendRawTx
"
$START_TX
"
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
##pokerbull_ContinueRawTx
pokerbull_ContinueRawTx
##pokerbull_QuitRawTx
##pokerbull_PlayRawTx
pokerbull_QuitRawTx
##pokerbull_QueryResult
pokerbull_PlayRawTx
pokerbull_QueryResult
}
}
function
main
()
{
function
main
()
{
...
...
plugin/dapp/retrieve/cmd/Makefile
0 → 100644
View file @
bbbba0f1
all
:
chmod
+x ./build.sh
./build.sh
$(OUT)
$(FLAG)
\ No newline at end of file
plugin/dapp/retrieve/cmd/build.sh
0 → 100644
View file @
bbbba0f1
#!/bin/sh
strpwd
=
$(
pwd
)
strcmd
=
${
strpwd
##*dapp/
}
strapp
=
${
strcmd
%/cmd*
}
OUT_DIR
=
"
${
1
}
/
$strapp
"
#FLAG=$2
mkdir
-p
"
${
OUT_DIR
}
"
cp
./build/
*
"
${
OUT_DIR
}
"
OUT_TESTDIR
=
"
${
1
}
/dapptest/
$strapp
"
mkdir
-p
"
${
OUT_TESTDIR
}
"
cp
./build/test-rpc.sh
"
${
OUT_TESTDIR
}
"
plugin/dapp/retrieve/cmd/build/test-rpc.sh
0 → 100644
View file @
bbbba0f1
#!/usr/bin/env bash
# shellcheck disable=SC2128
set
-e
set
-o
pipefail
MAIN_HTTP
=
""
CASE_ERR
=
""
#color
RED
=
'\033[1;31m'
GRE
=
'\033[1;32m'
NOC
=
'\033[0m'
echo_rst
()
{
if
[
"
$2
"
==
0
]
;
then
echo
-e
"
${
GRE
}
$1
ok
${
NOC
}
"
else
echo
-e
"
${
RED
}
$1
fail
${
NOC
}
"
CASE_ERR
=
"FAIL"
fi
}
function
block_wait
()
{
local
req
=
'"method":"Chain33.GetLastHeader","params":[]'
cur_height
=
$(
curl
-ksd
"{
$req
}"
${
MAIN_HTTP
}
| jq
".result.height"
)
expect
=
$((
cur_height
+
${
1
}))
local
count
=
0
while
true
;
do
new_height
=
$(
curl
-ksd
"{
$req
}"
${
MAIN_HTTP
}
| jq
".result.height"
)
if
[
"
${
new_height
}
"
-ge
"
${
expect
}
"
]
;
then
break
fi
count
=
$((
count
+
1
))
sleep
1
done
echo
"wait new block
$count
s, cur height=
$expect
,old=
$cur_height
"
}
function
query_tx
()
{
block_wait 1
local
txhash
=
"
$1
"
local
req
=
'"method":"Chain33.QueryTransaction","params":[{"hash":"'
"
$txhash
"
'"}]'
# echo "req=$req"
local times
=
10
while
true
;
do
ret
=
$(
curl
-ksd
"{
$req
}"
${
MAIN_HTTP
}
| jq
-r
".result.tx.hash"
)
echo
"====query tx=
${
1
}
, return=
$ret
"
if
[
"
${
ret
}
"
!=
"
${
1
}
"
]
;
then
block_wait 1
times
=
$((
times
-
1
))
if
[
$times
-le
0
]
;
then
echo
"====query tx=
$1
failed"
echo
"req=
$req
"
curl
-ksd
"{
$req
}"
${
MAIN_HTTP
}
exit
1
fi
else
echo
"====query tx=
$1
success"
break
fi
done
}
retrieve_Backup
()
{
tx
=
$(
curl
-ksd
'{"method":"retrieve.CreateRawRetrieveBackupTx","params":[{"backupAddr":"'
$1
'","defaultAddr":"'
$2
'","delayPeriod":$3}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer == "retrieve")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
signrawtx
"
$tx
"
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
}
retrieve_Prepare
()
{
tx
=
$(
curl
-ksd
'{"method":"retrieve.CreateRawRetrievePrepareTx","params":[{"backupAddr":"'
$1
'","defaultAddr":"'
$2
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer == "retrieve")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
signrawtx
"
$tx
"
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
}
retrieve_Perform
()
{
tx
=
$(
curl
-ksd
'{"method":"retrieve.CreateRawRetrievePerformTx","params":[{"backupAddr":"'
$1
'","defaultAddr":"'
$2
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer == "retrieve")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
signrawtx
"
$tx
"
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
}
retrieve_Cancel
()
{
tx
=
$(
curl
-ksd
'{"method":"retrieve.CreateRawRetrieveCancelTx","params":[{"backupAddr":"'
$1
'","defaultAddr":"'
$2
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer == "retrieve")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
signrawtx
"
$tx
"
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
}
retrieve_QueryResult
()
{
# data=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByID","payload":{"gameId":"'$GAME_ID'"}}]}' ${MAIN_HTTP} | jq -r ".result")
# ok=$(jq '(.game.gameId == "'$GAME_ID'")' <<<"$data")
#
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
#
# data=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByAddr","payload":{"addr":"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"}}]}' ${MAIN_HTTP} | jq -r ".result")
# [ "$data" != null ]
# echo_rst "$FUNCNAME" "$?"
#
# data=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByStatus","payload":{"status":"3"}}]}' ${MAIN_HTTP} | jq -r ".result")
# [ "$data" != null ]
echo_rst
"
$FUNCNAME
"
"
$?
"
}
chain33_ImportPrivkey
()
{
local
pri
=
$2
local
acc
=
$3
local
req
=
'"method":"Chain33.ImportPrivkey", "params":[{"privkey":"'
"
$pri
"
'", "label":"pokerbullimportkey1"}]'
echo
"#request:
$req
"
resp
=
$(
curl
-ksd
"{
$req
}"
"
$1
"
)
echo
"#response:
$resp
"
ok
=
$(
jq
'(.error|not) and (.result.label=="pokerbullimportkey1") and (.result.acc.addr == "'
"
$acc
"
'")'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
}
signrawtx
()
{
txHex
=
"
$1
"
priKey
=
"
$2
"
type
=
"
$3
"
local
req
=
'"method":"Chain33.SignRawTx","params":[{"privkey":"'
"
$priKey
"
'","txHex":"'
"
$txHex
"
'","expire":"120s"}]'
# echo "#request SignRawTx: $req"
signedTx
=
$(
curl
-ksd
"{
$req
}"
${
MAIN_HTTP
}
| jq
-r
".result"
)
# echo "signedTx=$signedTx"
if
[
"
$signedTx
"
!=
null
]
;
then
sendTx
"
$signedTx
"
else
echo
"signedTx null error"
fi
}
sendTx
()
{
signedTx
=
$1
local
req
=
'"method":"Chain33.SendTransaction","params":[{"token":"BTY","data":"'
"
$signedTx
"
'"}]'
# echo "#request sendTx: $req"
# curl -ksd "{$req}" ${MAIN_HTTP}
resp
=
$(
curl
-ksd
"{
$req
}"
${
MAIN_HTTP
})
err
=
$(
jq
'(.error)'
<<<
"
$resp
"
)
txhash
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
if
[
"
$err
"
==
null
]
;
then
# echo "tx hash: $txhash"
query_tx
"
$txhash
"
else
echo
"send tx error:
$err
"
fi
}
Chain33_SendToAddress
()
{
local
from
=
"
$1
"
local
to
=
"
$2
"
local
amount
=
$3
local
req
=
'"method":"Chain33.SendToAddress", "params":[{"from":"'
"
$from
"
'","to":"'
"
$to
"
'", "amount":'
"
$amount
"
', "note":"test\n"}]'
# echo "#request: $req"
resp
=
$(
curl
-ksd
"{
$req
}"
"
${
MAIN_HTTP
}
"
)
# echo "#response: $resp"
ok
=
$(
jq
'(.error|not) and (.result.hash|length==66)'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
hash
=
$(
jq
'(.result.hash)'
<<<
"
$resp
"
)
echo
"hash=
$hash
"
# query_tx "$hash"
}
init
()
{
ispara
=
$(
echo
'"'
"
${
MAIN_HTTP
}
"
'"'
| jq
'.|contains("8901")'
)
echo
"ipara=
$ispara
"
if
[
"
$ispara
"
==
true
]
;
then
retrieve_addr
=
$(
curl
-ksd
'{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.retrieve"}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
else
#chain33_ImportPrivkey "${MAIN_HTTP}" "0x9c451df9e5cb05b88b28729aeaaeb3169a2414097401fcb4c79c1971df734588" "1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY"
retrieve_addr
=
$(
curl
-ksd
'{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"retrieve"}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
fi
echo
"retrieveaddr=
$retrieve_addr
"
from
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
Chain33_SendToAddress
"
$from
"
"
$retrieve_addr
"
10000000000
from
=
"1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY"
Chain33_SendToAddress
"
$from
"
"
$retrieve_addr
"
10000000000
block_wait 1
}
function
run_test
()
{
retrieve_Backup
retrieve_Prepare
retrieve_Perform
retrieve_Cancel
retrieve_QueryResult
}
function
main
()
{
MAIN_HTTP
=
"
$1
"
echo
"=========== # retrieve rpc test ============="
echo
"ip=
$MAIN_HTTP
"
init
run_test
if
[
-n
"
$CASE_ERR
"
]
;
then
echo
-e
"
${
RED
}
=============retrieve Rpc Test Fail=============
${
NOC
}
"
exit
1
else
echo
-e
"
${
GRE
}
=============retrieve Rpc Test Pass==============
${
NOC
}
"
fi
}
main
"
$1
"
plugin/dapp/retrieve/c
ommands
/retrieve.go
→
plugin/dapp/retrieve/c
md
/retrieve.go
100755 → 100644
View file @
bbbba0f1
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// license that can be found in the LICENSE file.
package
c
ommands
package
c
md
import
(
import
(
"fmt"
"fmt"
...
...
plugin/dapp/retrieve/plugin.go
View file @
bbbba0f1
...
@@ -6,7 +6,7 @@ package retrieve
...
@@ -6,7 +6,7 @@ package retrieve
import
(
import
(
"github.com/33cn/chain33/pluginmgr"
"github.com/33cn/chain33/pluginmgr"
"github.com/33cn/plugin/plugin/dapp/retrieve/c
ommands
"
"github.com/33cn/plugin/plugin/dapp/retrieve/c
md
"
"github.com/33cn/plugin/plugin/dapp/retrieve/executor"
"github.com/33cn/plugin/plugin/dapp/retrieve/executor"
"github.com/33cn/plugin/plugin/dapp/retrieve/rpc"
"github.com/33cn/plugin/plugin/dapp/retrieve/rpc"
"github.com/33cn/plugin/plugin/dapp/retrieve/types"
"github.com/33cn/plugin/plugin/dapp/retrieve/types"
...
@@ -17,7 +17,7 @@ func init() {
...
@@ -17,7 +17,7 @@ func init() {
Name
:
types
.
RetrieveX
,
Name
:
types
.
RetrieveX
,
ExecName
:
executor
.
GetName
(),
ExecName
:
executor
.
GetName
(),
Exec
:
executor
.
Init
,
Exec
:
executor
.
Init
,
Cmd
:
c
ommands
.
RetrieveCmd
,
Cmd
:
c
md
.
RetrieveCmd
,
RPC
:
rpc
.
Init
,
RPC
:
rpc
.
Init
,
})
})
}
}
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