-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.sample.php
133 lines (115 loc) · 4.44 KB
/
config.sample.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
require_once __DIR__ . '/vendor/autoload.php';
use deemru\WavesKit;
$chainId = 'T';
$seed = 'manage manual recall harvest series desert melt police rose hollow moral pledge kitten position add vecro';
$database = __DIR__ . '/vecro.sqlite';
$alias = 'vecrotest';
$aliasInit = "init@$alias";
$aliasRandom = "random@$alias";
$assetInitName = "R-$alias";
$assetRandomName = "S-$alias";
// define explicitly to bypass initVECRO() call
//$assetInit = '21eV9L5qsU2H1jwCbDSkzWUuFyYvfNFaycSjLYPaZLHD';
//$assetRandom = '7ZFZjR18tF1gdmN73oKbMo9FSWLrAz6ocDMXsd13v5oJ';
$nodes =
[
'https://testnode1.wavesnodes.com',
'https://testnode2.wavesnodes.com',
'https://testnode3.wavesnodes.com',
'https://testnode4.wavesnodes.com',
];
define( 'IREALLYKNOWWHAT_RSEED_MEANS', true );
$wk = new WavesKit( $chainId );
$wk->setNodeAddress( $nodes[0], 1, array_slice( $nodes, 1 ) );
$wk->setSeed( $seed );
$wk->log( 's', 'VECRO @ ' . $wk->getAddress() );
$wk->setBestNode();
$wk->log( 'i', 'best node = ' . $wk->getNodeAddress() );
if( !isset( $assetInit ) || !isset( $assetRandom ) )
{
$assetInit = null;
$assetRandom = null;
$script = file_get_contents( 'vecro.ride' );
initVECRO( $wk, $alias, $aliasInit, $aliasRandom, $assetInitName, $assetRandomName, $assetInit, $assetRandom, $script );
}
function initVECRO( $wk, $alias, $aliasInit, $aliasRandom, $assetInitName, $assetRandomName, &$assetInit, &$assetRandom, $script )
{
$aliases = [ $alias, $aliasInit, $aliasRandom ];
foreach( $aliases as $a )
{
if( $wk->getAddress() === ( $address = $wk->getAddressByAlias( $a ) ) )
{
$wk->log( 's', "alias \"$a\" OK" );
continue;
}
$wk->log( 'i', "alias binding \"$a\"" );
$tx = $wk->txAlias( $a );
$tx['fee'] = $wk->calculateFee( $tx );
$tx = $wk->txSign( $tx );
$tx = $wk->txBroadcast( $tx );
if( $tx === false )
exit( $wk->log( 'e', "alias binding \"$a\"" ) );
$wk->log( 's', "$a = {$tx['id']}" );
}
$balance = $wk->balance();
$assetInit = null;
$assetRandom = null;
foreach( $balance as $asset => $info )
{
if( isset( $info['issueTransaction'] ) && $address === $info['issueTransaction']['sender'] )
{
$issueTx = $info['issueTransaction'];
if( $address === $issueTx['sender'] )
{
if( $issueTx['name'] === $assetInitName )
{
$assetInit = $asset;
$wk->log( 's', "$assetInitName = $assetInit" );
}
elseif( $issueTx['name'] === $assetRandomName )
{
$assetRandom = $asset;
$wk->log( 's', "$assetRandomName = $assetRandom" );
}
}
}
}
if( !isset( $assetInit ) )
{
$tx = $wk->txIssue( $assetInitName, "$alias`s token for R-value transfering via attachment", 100000000, 0, true );
$tx['fee'] = $wk->calculateFee( $tx );
$tx = $wk->txSign( $tx );
$tx = $wk->txBroadcast( $tx );
if( $tx === false )
exit( $wk->log( 'e', "token issue \"$assetInitName\"" ) );
$assetInit = $tx['id'];
$wk->log( 's', "$assetInitName = $assetInit" );
}
if( !isset( $assetRandom ) )
{
$tx = $wk->txIssue( $assetRandomName, "$alias`s token for S-value transfering via attachment", 100000000, 0, true );
$tx['fee'] = $wk->calculateFee( $tx );
$tx = $wk->txSign( $tx );
$tx = $wk->txBroadcast( $tx );
if( $tx === false )
exit( $wk->log( 'e', "token issue \"$assetRandomName\"" ) );
$assetRandom = $tx['id'];
$wk->log( 's', "$assetRandomName = $assetRandom" );
}
if( false === ( $addressScript = $wk->getAddressScript() ) )
{
$script = sprintf( $script, $aliasInit, $aliasRandom, $assetInit, $assetRandom );
if( false === ( $script = $wk->compile( $script ) ) )
exit( $wk->log( 'e', "compile failed" ) );
$tx = $wk->txAddressScript( $script['script'] );
$tx['fee'] = $wk->calculateFee( $tx );
$tx = $wk->txSign( $tx );
$tx = $wk->txBroadcast( $tx );
if( $tx === false )
exit( $wk->log( 'e', 'txAddressScript' ) );
$wk->log( 's', "script = {$tx['id']}" );
}
if( isset( $addressScript['complexity'] ) )
$wk->log( 's', "script (complexity:{$addressScript['complexity']}) OK" );
}