Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
0cf2fbac
Y
YTBP
项目概览
YottaChain
/
YTBP
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
YTBP
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
0cf2fbac
编写于
5月 12, 2018
作者:
D
Daniel Larimer
提交者:
GitHub
5月 12, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2971 from EOSIO/send-deferred-replace-parameter
send_deferred_transaction : new parameter "replace_existing"
上级
3aad565b
f30ebc88
变更
12
显示空白变更内容
内联
并排
Showing
12 changed file
with
50 addition
and
21 deletion
+50
-21
contracts/eosio.msig/eosio.msig.cpp
contracts/eosio.msig/eosio.msig.cpp
+0
-7
contracts/eosio.system/delegate_bandwidth.cpp
contracts/eosio.system/delegate_bandwidth.cpp
+1
-1
contracts/eosiolib/transaction.h
contracts/eosiolib/transaction.h
+1
-2
contracts/eosiolib/transaction.hpp
contracts/eosiolib/transaction.hpp
+2
-2
contracts/test_api/test_api.cpp
contracts/test_api/test_api.cpp
+1
-0
contracts/test_api/test_api.hpp
contracts/test_api/test_api.hpp
+1
-0
contracts/test_api/test_transaction.cpp
contracts/test_api/test_transaction.cpp
+10
-1
libraries/chain/apply_context.cpp
libraries/chain/apply_context.cpp
+2
-1
libraries/chain/include/eosio/chain/apply_context.hpp
libraries/chain/include/eosio/chain/apply_context.hpp
+1
-1
libraries/chain/include/eosio/chain/exceptions.hpp
libraries/chain/include/eosio/chain/exceptions.hpp
+2
-0
libraries/chain/wasm_interface.cpp
libraries/chain/wasm_interface.cpp
+3
-3
unittests/api_tests.cpp
unittests/api_tests.cpp
+26
-3
未找到文件。
contracts/eosio.msig/eosio.msig.cpp
浏览文件 @
0cf2fbac
...
...
@@ -111,13 +111,6 @@ void multisig::exec( account_name proposer, name proposal_name, account_name exe
ds
>>
trx_header
;
eosio_assert
(
trx_header
.
expiration
>=
now
(),
"transaction expired"
);
// Updating expiration is not necessary because the expiration field of a deferred transaction is modified to be valid anyway
/*
trx_header.expiration = now() + 60;
ds.seekp(0);
ds << trx_header;
*/
bytes
packed_provided_approvals
=
pack
(
prop_it
->
provided_approvals
);
auto
res
=
::
check_transaction_authorization
(
prop_it
->
packed_transaction
.
data
(),
prop_it
->
packed_transaction
.
size
(),
(
const
char
*
)
0
,
0
,
...
...
contracts/eosio.system/delegate_bandwidth.cpp
浏览文件 @
0cf2fbac
...
...
@@ -366,7 +366,7 @@ namespace eosiosystem {
eosio
::
transaction
out
;
out
.
actions
.
emplace_back
(
permission_level
{
from
,
N
(
active
)
},
_self
,
N
(
refund
),
from
);
out
.
delay_sec
=
refund_delay
;
out
.
send
(
from
,
receiver
);
out
.
send
(
from
,
receiver
,
true
);
const
auto
&
fromv
=
_voters
.
get
(
from
);
...
...
contracts/eosiolib/transaction.h
浏览文件 @
0cf2fbac
...
...
@@ -58,8 +58,7 @@ extern "C" {
*
* @{
*/
void
send_deferred
(
const
uint128_t
&
sender_id
,
account_name
payer
,
const
char
*
serialized_transaction
,
size_t
size
);
void
send_deferred
(
const
uint128_t
&
sender_id
,
account_name
payer
,
const
char
*
serialized_transaction
,
size_t
size
,
uint32_t
replace_existing
=
0
);
void
cancel_deferred
(
const
uint128_t
&
sender_id
);
...
...
contracts/eosiolib/transaction.hpp
浏览文件 @
0cf2fbac
...
...
@@ -42,9 +42,9 @@ namespace eosio {
public:
transaction
(
time
exp
=
now
()
+
60
)
:
transaction_header
(
exp
)
{}
void
send
(
uint64_t
sender_id
,
account_name
payer
)
const
{
void
send
(
uint64_t
sender_id
,
account_name
payer
,
bool
replace_existing
=
false
)
const
{
auto
serialize
=
pack
(
*
this
);
send_deferred
(
sender_id
,
payer
,
serialize
.
data
(),
serialize
.
size
());
send_deferred
(
sender_id
,
payer
,
serialize
.
data
(),
serialize
.
size
()
,
replace_existing
);
}
vector
<
action
>
context_free_actions
;
...
...
contracts/test_api/test_api.cpp
浏览文件 @
0cf2fbac
...
...
@@ -136,6 +136,7 @@ extern "C" {
WASM_TEST_HANDLER_EX
(
test_transaction
,
send_action_sender
);
WASM_TEST_HANDLER
(
test_transaction
,
deferred_print
);
WASM_TEST_HANDLER_EX
(
test_transaction
,
send_deferred_transaction
);
WASM_TEST_HANDLER_EX
(
test_transaction
,
send_deferred_transaction_replace
);
WASM_TEST_HANDLER
(
test_transaction
,
send_deferred_tx_with_dtt_action
);
WASM_TEST_HANDLER
(
test_transaction
,
cancel_deferred_transaction
);
WASM_TEST_HANDLER
(
test_transaction
,
send_cf_action
);
...
...
contracts/test_api/test_api.hpp
浏览文件 @
0cf2fbac
...
...
@@ -167,6 +167,7 @@ struct test_transaction {
static
void
send_action_sender
(
uint64_t
receiver
,
uint64_t
code
,
uint64_t
action
);
static
void
deferred_print
();
static
void
send_deferred_transaction
(
uint64_t
receiver
,
uint64_t
code
,
uint64_t
action
);
static
void
send_deferred_transaction_replace
(
uint64_t
receiver
,
uint64_t
code
,
uint64_t
action
);
static
void
send_deferred_tx_with_dtt_action
();
static
void
cancel_deferred_transaction
();
static
void
send_cf_action
();
...
...
contracts/test_api/test_transaction.cpp
浏览文件 @
0cf2fbac
...
...
@@ -245,6 +245,15 @@ void test_transaction::send_deferred_transaction(uint64_t receiver, uint64_t, ui
trx
.
send
(
0xffffffffffffffff
,
receiver
);
}
void
test_transaction
::
send_deferred_transaction_replace
(
uint64_t
receiver
,
uint64_t
,
uint64_t
)
{
using
namespace
eosio
;
auto
trx
=
transaction
();
test_action_action
<
N
(
testapi
),
WASM_TEST_ACTION
(
"test_transaction"
,
"deferred_print"
)
>
test_action
;
trx
.
actions
.
emplace_back
(
vector
<
permission_level
>
{{
N
(
testapi
),
N
(
active
)}},
test_action
);
trx
.
delay_sec
=
2
;
trx
.
send
(
0xffffffffffffffff
,
receiver
,
true
);
}
void
test_transaction
::
send_deferred_tx_with_dtt_action
()
{
using
namespace
eosio
;
dtt_action
dtt_act
;
...
...
@@ -258,7 +267,7 @@ void test_transaction::send_deferred_tx_with_dtt_action() {
auto
trx
=
transaction
();
trx
.
actions
.
emplace_back
(
deferred_act
);
trx
.
delay_sec
=
dtt_act
.
delay_sec
;
trx
.
send
(
0xffffffffffffffff
,
dtt_act
.
payer
);
trx
.
send
(
0xffffffffffffffff
,
dtt_act
.
payer
,
true
);
}
...
...
libraries/chain/apply_context.cpp
浏览文件 @
0cf2fbac
...
...
@@ -214,7 +214,7 @@ void apply_context::execute_context_free_inline( action&& a ) {
}
void
apply_context
::
schedule_deferred_transaction
(
const
uint128_t
&
sender_id
,
account_name
payer
,
transaction
&&
trx
)
{
void
apply_context
::
schedule_deferred_transaction
(
const
uint128_t
&
sender_id
,
account_name
payer
,
transaction
&&
trx
,
bool
replace_existing
)
{
FC_ASSERT
(
trx
.
context_free_actions
.
size
()
==
0
,
"context free actions are not currently allowed in generated transactions"
);
trx
.
expiration
=
control
.
pending_block_time
()
+
fc
::
microseconds
(
999'999
);
// Rounds up to nearest second (makes expiration check unnecessary)
trx
.
set_reference_block
(
control
.
head_block_id
());
// No TaPoS check necessary
...
...
@@ -257,6 +257,7 @@ void apply_context::schedule_deferred_transaction( const uint128_t& sender_id, a
uint32_t
trx_size
=
0
;
auto
&
d
=
control
.
db
();
if
(
auto
ptr
=
d
.
find
<
generated_transaction_object
,
by_sender_id
>
(
boost
::
make_tuple
(
receiver
,
sender_id
))
)
{
EOS_ASSERT
(
replace_existing
,
deferred_tx_duplicate
,
"deferred transaction with the same sender_id and payer already exists"
);
d
.
modify
<
generated_transaction_object
>
(
*
ptr
,
[
&
](
auto
&
gtx
)
{
gtx
.
sender
=
receiver
;
gtx
.
sender_id
=
sender_id
;
...
...
libraries/chain/include/eosio/chain/apply_context.hpp
浏览文件 @
0cf2fbac
...
...
@@ -476,7 +476,7 @@ class apply_context {
void
exec
();
void
execute_inline
(
action
&&
a
);
void
execute_context_free_inline
(
action
&&
a
);
void
schedule_deferred_transaction
(
const
uint128_t
&
sender_id
,
account_name
payer
,
transaction
&&
trx
);
void
schedule_deferred_transaction
(
const
uint128_t
&
sender_id
,
account_name
payer
,
transaction
&&
trx
,
bool
replace_existing
);
void
cancel_deferred_transaction
(
const
uint128_t
&
sender_id
,
account_name
sender
);
void
cancel_deferred_transaction
(
const
uint128_t
&
sender_id
)
{
cancel_deferred_transaction
(
sender_id
,
receiver
);
}
...
...
libraries/chain/include/eosio/chain/exceptions.hpp
浏览文件 @
0cf2fbac
...
...
@@ -156,6 +156,8 @@ namespace eosio { namespace chain {
3040007
,
"Invalid Reference Block"
)
FC_DECLARE_DERIVED_EXCEPTION
(
tx_duplicate
,
transaction_exception
,
3040008
,
"duplicate transaction"
)
FC_DECLARE_DERIVED_EXCEPTION
(
deferred_tx_duplicate
,
transaction_exception
,
3040009
,
"duplicate deferred transaction"
)
FC_DECLARE_DERIVED_EXCEPTION
(
action_validate_exception
,
chain_exception
,
...
...
libraries/chain/wasm_interface.cpp
浏览文件 @
0cf2fbac
...
...
@@ -1250,11 +1250,11 @@ class transaction_api : public context_aware_api {
context
.
execute_context_free_inline
(
std
::
move
(
act
));
}
void
send_deferred
(
const
uint128_t
&
sender_id
,
account_name
payer
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
void
send_deferred
(
const
uint128_t
&
sender_id
,
account_name
payer
,
array_ptr
<
char
>
data
,
size_t
data_len
,
uint32_t
replace_existing
)
{
try
{
transaction
trx
;
fc
::
raw
::
unpack
<
transaction
>
(
data
,
data_len
,
trx
);
context
.
schedule_deferred_transaction
(
sender_id
,
payer
,
std
::
move
(
trx
));
context
.
schedule_deferred_transaction
(
sender_id
,
payer
,
std
::
move
(
trx
)
,
replace_existing
);
}
FC_CAPTURE_AND_RETHROW
((
fc
::
to_hex
(
data
,
data_len
)));
}
...
...
@@ -1754,7 +1754,7 @@ REGISTER_INTRINSICS(context_free_transaction_api,
REGISTER_INTRINSICS
(
transaction_api
,
(
send_inline
,
void
(
int
,
int
)
)
(
send_context_free_inline
,
void
(
int
,
int
)
)
(
send_deferred
,
void
(
int
,
int64_t
,
int
,
int
)
)
(
send_deferred
,
void
(
int
,
int64_t
,
int
,
int
,
int32_t
)
)
(
cancel_deferred
,
void
(
int
)
)
);
...
...
unittests/api_tests.cpp
浏览文件 @
0cf2fbac
...
...
@@ -879,13 +879,36 @@ BOOST_FIXTURE_TEST_CASE(deferred_transaction_tests, TESTER) { try {
produce_blocks
(
10
);
//schedule twice (second deferred transaction should replace first one)
//schedule twice
without replace_existing flag
(second deferred transaction should replace first one)
{
transaction_trace_ptr
trace
;
uint32_t
count
=
0
;
auto
c
=
control
->
applied_transaction
.
connect
([
&
](
const
transaction_trace_ptr
&
t
)
{
if
(
t
&&
t
->
scheduled
)
{
trace
=
t
;
++
count
;
}
}
);
CALL_TEST_FUNCTION
(
*
this
,
"test_transaction"
,
"send_deferred_transaction"
,
{});
CALL_TEST_FUNCTION
(
*
this
,
"test_transaction"
,
"send_deferred_transaction"
,
{});
BOOST_CHECK_THROW
(
CALL_TEST_FUNCTION
(
*
this
,
"test_transaction"
,
"send_deferred_transaction"
,
{}),
deferred_tx_duplicate
);
produce_blocks
(
3
);
//check that only one deferred transaction executed
auto
dtrxs
=
control
->
get_scheduled_transactions
();
BOOST_CHECK_EQUAL
(
dtrxs
.
size
(),
1
);
for
(
const
auto
&
trx
:
dtrxs
)
{
control
->
push_scheduled_transaction
(
trx
,
fc
::
time_point
::
maximum
());
}
BOOST_CHECK_EQUAL
(
1
,
count
);
BOOST_CHECK
(
trace
);
BOOST_CHECK_EQUAL
(
1
,
trace
->
action_traces
.
size
()
);
c
.
disconnect
();
}
produce_blocks
(
10
);
//schedule twice with replace_existing flag (second deferred transaction should replace first one)
{
transaction_trace_ptr
trace
;
uint32_t
count
=
0
;
auto
c
=
control
->
applied_transaction
.
connect
([
&
](
const
transaction_trace_ptr
&
t
)
{
if
(
t
&&
t
->
scheduled
)
{
trace
=
t
;
++
count
;
}
}
);
CALL_TEST_FUNCTION
(
*
this
,
"test_transaction"
,
"send_deferred_transaction_replace"
,
{});
CALL_TEST_FUNCTION
(
*
this
,
"test_transaction"
,
"send_deferred_transaction_replace"
,
{});
produce_blocks
(
3
);
//check that only one deferred transaction executed
...
...
@@ -966,7 +989,7 @@ BOOST_FIXTURE_TEST_CASE(deferred_transaction_tests, TESTER) { try {
(
"code"
,
name
(
dtt_act3
.
deferred_account
))
(
"type"
,
name
(
dtt_act3
.
deferred_action
))
(
"requirement"
,
name
(
dtt_act3
.
permission_name
)));
CALL_TEST_FUNCTION
(
*
this
,
"test_transaction"
,
"send_deferred_tx_with_dtt_action"
,
fc
::
raw
::
pack
(
dtt_act3
));
CALL_TEST_FUNCTION
(
*
this
,
"test_transaction"
,
"send_deferred_tx_with_dtt_action"
,
fc
::
raw
::
pack
(
dtt_act3
));
//will replace existing transaction
// If we make testapi account to be priviledged account:
// - the deferred transaction will work no matter who is the payer
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录