Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
token
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
wallet
token
Commits
b71d7bf7
Commit
b71d7bf7
authored
Aug 27, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
跨链交易
parent
e71c922b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
252 additions
and
0 deletions
+252
-0
CrossChainController.php
api/controllers/CrossChainController.php
+133
-0
CoinCrossChain.php
common/models/psources/CoinCrossChain.php
+47
-0
CrossChainController.php
console/controllers/CrossChainController.php
+72
-0
No files found.
api/controllers/CrossChainController.php
0 → 100644
View file @
b71d7bf7
<?php
namespace
api\controllers
;
use
api\base\BaseController
;
use
common\models\psources\CoinAirDropTrade
;
use
common\models\psources\CoinCrossChain
;
use
common\service\chain33\Chain33Service
;
use
Yii
;
use
yii\db\Exception
;
class
CrossChainController
extends
BaseController
{
public
function
actionTransfer
()
{
$code
=
-
1
;
$msg
=
'fail'
;
$request
=
Yii
::
$app
->
request
;
if
(
!
$request
->
isPost
)
{
$msg
=
'请求错误!'
;
goto
doEnd
;
}
$post
=
$request
->
post
();
if
(
3
!=
count
(
$post
[
'txs'
]))
{
$msg
=
'交易笔数错误!'
;
goto
doEnd
;
}
$data
[
'is_with_draw'
]
=
$post
[
'isWithdraw'
];
$data
[
'address'
]
=
$post
[
'address'
];
$data
[
'transfer_number'
]
=
date
(
'YmdHis'
)
.
self
::
getrandnums
();
$model
=
CoinCrossChain
::
find
()
->
where
([
'address'
=>
$post
[
'address'
],
'current_step'
=>
CoinCrossChain
::
STEP_DEFAULT
,
'is_with_draw'
=>
CoinCrossChain
::
RECHARGE
])
->
one
();
if
(
$model
)
{
$msg
=
'存在未完成的交易!'
;
goto
doEnd
;
}
$model
=
new
CoinCrossChain
();
foreach
(
$post
[
'txs'
]
as
$key
=>
$val
)
{
if
(
1
==
$val
[
'step'
])
{
$seq
=
'first'
;
}
else
if
(
2
==
$val
[
'step'
])
{
$seq
=
'second'
;
}
else
if
(
3
==
$val
[
'step'
])
{
$seq
=
'thrid'
;
}
else
{
}
$data
[
'txhex_'
.
$seq
]
=
$val
[
'tx'
];
$data
[
'transfer_url_'
.
$seq
]
=
$val
[
'url'
];
}
$model
->
setScenario
(
CoinCrossChain
::
SCENARIOS_CREATE
);
if
(
$model
->
load
(
$data
,
''
)
&&
$model
->
save
())
{
$msg
=
'success'
;
$code
=
0
;
}
else
{
$msg
=
current
(
$model
->
firstErrors
);
}
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
];
}
public
function
actionTransferStatus
()
{
$code
=
-
1
;
$msg
=
'fail'
;
$data
=
null
;
$request
=
Yii
::
$app
->
request
;
if
(
!
$request
->
isGet
)
{
$msg
=
'请求错误!'
;
goto
doEnd
;
}
$address
=
$request
->
get
(
'address'
,
''
);
$is_with_draw
=
$request
->
get
(
'isWithdraw'
,
''
);
if
(
empty
(
$address
))
{
$msg
=
'参数错误!'
;
goto
doEnd
;
}
$model
=
CoinCrossChain
::
find
()
->
where
([
'address'
=>
$address
,
'is_with_draw'
=>
$is_with_draw
])
->
orderBy
(
"id desc"
)
->
limit
(
1
)
->
asArray
()
->
one
();
if
(
empty
(
$model
))
{
$msg
=
'数据不存在!'
;
goto
doEnd
;
}
if
(
false
==
$model
[
'txhash'
]
&&
false
==
$model
[
'msg'
])
{
$data
=
[
'step'
=>
$model
[
'current_step'
]
];
$code
=
0
;
$msg
=
'交易尚未执行'
;
goto
doEnd
;
}
if
(
false
==
$model
[
'txhash'
]
&&
false
!=
$model
[
'msg'
])
{
$data
=
[
'step'
=>
$model
[
'current_step'
]
];
$msg
=
$model
[
'msg'
];
goto
doEnd
;
}
if
(
true
==
$model
[
'txhash'
]
&&
false
==
$model
[
'msg'
])
{
$data
=
[
'step'
=>
$model
[
'current_step'
]
];
$code
=
0
;
$msg
=
$model
[
'txhash'
];
goto
doEnd
;
}
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'data'
=>
$data
];
}
public
static
function
getrandnums
()
{
$arr
=
array
();
while
(
count
(
$arr
)
<
6
)
{
$arr
[]
=
rand
(
0
,
9
);
$arr
=
array_unique
(
$arr
);
}
return
implode
(
""
,
$arr
);
}
}
\ No newline at end of file
common/models/psources/CoinCrossChain.php
0 → 100644
View file @
b71d7bf7
<?php
namespace
common\models\psources
;
use
Yii
;
use
common\core\BaseActiveRecord
;
class
CoinCrossChain
extends
BaseActiveRecord
{
const
STEP_DEFAULT
=
0
;
const
STEP_FIRST
=
1
;
const
STEP_SECOND
=
2
;
const
STEP_THRID
=
3
;
const
WITHDRAW
=
0
;
const
RECHARGE
=
1
;
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
public
static
function
tableName
()
{
return
'{{%coin_cross_chain}}'
;
}
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
public
function
rules
()
{
return
[
[[
'is_with_draw'
,
'address'
,
'txhex_first'
,
'transfer_url_first'
,
'txhex_second'
,
'transfer_url_second'
,
'txhex_thrid'
,
'transfer_url_thrid'
],
'required'
],
[
'transfer_number'
,
'safe'
]
];
}
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'is_with_draw'
,
'address'
,
'txhex_first'
,
'transfer_url_first'
,
'txhex_second'
,
'transfer_url_second'
,
'txhex_thrid'
,
'transfer_url_thrid'
,
'transfer_number'
],
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
}
}
console/controllers/CrossChainController.php
0 → 100644
View file @
b71d7bf7
<?php
namespace
console\controllers
;
use
common\models\psources\CoinCrossChain
;
use
Yii
;
use
yii\console\Controller
;
use
common\service\chain33\Chain33Service
;
class
CrossChainController
extends
Controller
{
/**
* 自动交易
*
* @return array
*/
public
function
actionAutoTransfer
()
{
$model
=
CoinCrossChain
::
find
()
->
where
([
'txhash'
=>
"0"
])
->
limit
(
20
)
->
asArray
()
->
all
();
if
(
empty
(
$model
))
{
echo
date
(
'Y-m-d H:i:s'
)
.
'暂无跨链交易计划'
.
PHP_EOL
;
return
0
;
}
foreach
(
$model
as
$key
=>
$val
)
{
go
(
function
()
use
(
$val
)
{
\Co
::
sleep
(
0.5
);
if
(
1
==
$val
[
'step'
])
{
$seq
=
'first'
;
}
else
if
(
2
==
$val
[
'step'
])
{
$seq
=
'second'
;
}
else
if
(
3
==
$val
[
'step'
])
{
$seq
=
'thrid'
;
}
else
{
}
$node_params
=
$val
[
'transfer_url_'
.
$seq
];
$node_params
=
Yii
::
$app
->
params
[
'chain_parallel'
][
'wasm'
][
$val
[
'coin_name'
]
.
'_wallet'
];
$service
=
new
Chain33Service
(
$node_params
);
$txHex
=
$val
[
'txhex_'
.
$seq
];
$privkey
=
'72c3879f1f9b523f266a9545b69bd41c0251483a93e21e348e85118afe17a5e21'
;
$expire
=
'1m'
;
$signRawTx
=
$service
->
signRawTx
(
$privkey
,
$txHex
,
$expire
);
if
(
0
!=
$signRawTx
[
'code'
])
{
$txhash
=
'0'
;
$msg
=
$signRawTx
[
'msg'
];
goto
doEnd
;
}
$sign_str
=
$signRawTx
[
'result'
];
$result
=
$service
->
sendTransaction
(
$sign_str
);
if
(
0
!=
$result
[
'code'
])
{
$txhash
=
'0'
;
$msg
=
$result
[
'msg'
];
goto
doEnd
;
}
$txhash
=
$result
[
'result'
];
$msg
=
'success'
;
doEnd
:
$currentModel
=
CoinAirDropTransfer
::
findOne
(
$id
);
$currentModel
->
txhash
=
$txhash
;
$currentModel
->
msg
=
$msg
;
$currentModel
->
save
();
});
}
return
0
;
}
}
\ No newline at end of file
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