-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path403_aggregate_comp_payload.html
242 lines (207 loc) · 7.97 KB
/
403_aggregate_comp_payload.html
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0">
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous">
</head>
<body>
<div class="container">
<h1>3.6 社会実装のヒント</h1>
<h3>トレーサビリティ</h3>
<!-- div block1 -->
<h3>deposit to</h3>
<div><span id="address"></span> <button id="button_faucet" class="btn btn-primary" type="button">蛇口</button></div>
<div class="collapse" id="result1">
<button id="button1" class="btn btn-primary" type="button" disabled>
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
承認中...
</button>
</div>
<!-- div block2 -->
<div class="collapse" id="result2">
<h3>aliceSignedTx</h3><textarea id="aliceSignedTx" rows="8" class="form-control"></textarea>
<h3>aliceSignedTxHash</h3><div><input type="text" id="aliceSignedTxHash" class="form-control"></div>
<button id="button2" class="btn btn-primary" type="button">Bob署名</button>
</div>
<!-- div block3 -->
<div class="collapse" id="result3">
<h3>bobSignedTxSignature</h3><textarea id="bobSignedTxSignature" rows="2" class="form-control"></textarea>
<h3>bobSignedTxSigner</h3><textarea id="bobSignedTxSigner" rows="1" class="form-control"></textarea>
<button id="button3" class="btn btn-primary" type="button">アナウンス</button>
</div>
<div class="collapse" id="result4">
<h3>signedTx</h3><textarea id="signedTx" rows="8" class="form-control"></textarea>
<h3>status</h3><div id="status"><ul></ul></div>
<div id="wait4" class="spinner-border text-primary" role="status">
<span class="sr-only">承認中...</span>
</div>
</div>
<!-- div block5 -->
<div class="collapse" id="result5">
<h3>confirmed</h3><div id="confirmed"><ul></ul></div>
<h3>account</h3><div id="account"><ul></ul></div>
</div>
</div>
<script
src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous">
</script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous">
</script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous">
</script>
<script src="symbol-sdk-0.17.3.js"></script>
<script>$(function() {
const nem = require("/node_modules/symbol-sdk");
const rxjs = require("/node_modules/rxjs/operators");
const NODE = 'https://sym-test.opening-line.jp:3001';
const GENERATION_HASH = "44D2225B8932C9A96DCB13508CBCDFFA9A9663BFBA2354FEEC8FCFCB7E19846C";
const alice = nem.Account.generateNewAccount(nem.NetworkType.TEST_NET);
const bob = nem.Account.generateNewAccount(nem.NetworkType.TEST_NET);
const carol = nem.Account.generateNewAccount(nem.NetworkType.TEST_NET);
$('#address').text(alice.address.address);
const wsEndpoint = NODE.replace('https', 'wss');
const listener = new nem.Listener(wsEndpoint, WebSocket);
var isInit = true;
listener.open().then(() => {
setInterval(function(){listener.newBlock()}, 30000);
listener
.unconfirmedAdded(alice.address)
.subscribe(_=> $('#result1').collapse('show'),err => console.error(err));
listener
.confirmed(alice.address)
.subscribe(
function(_){
if(isInit){
$('#button1').prop("disabled", false);
$('#button1').empty();
$('#button1').text("送信");
isInit = false;
}else{
$('#wait2').remove();
$('#result3').collapse('show');
}
},
err => console.error(err)
);
});
function process(){
const sendAmount =
new nem.Mosaic(
new nem.MosaicId('747B276C30626442'),
nem.UInt64.fromUint(10000000)
)
const send2Amount =
new nem.Mosaic(
new nem.MosaicId('747B276C30626442'),
nem.UInt64.fromUint(1000000)
)
const aliceTx = nem.TransferTransaction.create(nem.Deadline.create(), bob.address, [sendAmount], nem.PlainMessage.create('alice to bob'), nem.NetworkType.TEST_NET);
const bobTx = nem.TransferTransaction.create(nem.Deadline.create(), carol.address, [send2Amount], nem.PlainMessage.create('bob to carol'), nem.NetworkType.TEST_NET);
//署名台帳作成
const aggregateTransaction = nem.AggregateTransaction.createComplete(
nem.Deadline.create(),
[
aliceTx.toAggregate(alice.publicAccount),
bobTx.toAggregate(bob.publicAccount)
],
nem.NetworkType.TEST_NET,
[],
nem.UInt64.fromUint(100000)
);
//Aliceで署名してシリアライズをBobに渡す
const aliceSignedTx = aggregateTransaction.signWith(alice, GENERATION_HASH);
$('#aliceSignedTx').val(aliceSignedTx.payload);
$('#aliceSignedTxHash').val(aliceSignedTx.hash);
}
function process2(){
//別端末でBobが署名
const bobSignedTx = nem.CosignatureTransaction.signTransactionPayload(bob, $('#aliceSignedTx').val(), GENERATION_HASH);
$('#bobSignedTxSignature').val(bobSignedTx.signature);
$('#bobSignedTxSigner').val(bobSignedTx.signerPublicKey);
console.log(bobSignedTx);
}
function process3(){
//Alice側でまとめてTx再作成→アナウンス
const cosignSignedTxs = [
new nem.CosignatureSignedTransaction(
$('#aliceSignedTxHash').val(),
$('#bobSignedTxSignature').val(),
$('#bobSignedTxSigner').val()
)
];
const recreatedTx = nem.TransactionMapping.createFromPayload($('#aliceSignedTx').val());
const signedTx = recreatedTx.signTransactionGivenSignatures(alice, cosignSignedTxs, GENERATION_HASH);
console.log(signedTx.payload);
const address = alice.address.address ;
const hash = signedTx.hash
const pubkey = alice.publicKey ;
$('#signedTx').val(signedTx.payload);
$('#status ul').append(strLi(NODE,'/transaction/' + hash + '/status' ,hash + '/status'));
$('#confirmed ul').append(strLi(NODE,'/transaction/' + hash ,hash ));
$('#account ul').append(strLi(NODE,'/account/' + pubkey ,address ));
$('#account ul').append(strLi(NODE,'/account/' + pubkey + '/transactions' ,address + '/transactions'));
const transactionHttp = new nem.TransactionHttp(NODE);
transactionHttp
.announce(signedTx)
.subscribe(x =>{
console.log(x);
},
err => console.error(err)
);
listener
.confirmed(alice.address)
.subscribe(_ => {
$('#wait4').remove();
$('#result5').collapse('show');
},
err => console.error(err)
);
}
function strLi(node,href,text){
return '<li><a target="_blank" href="' + node + href + '">' + text + '</a></li>';
}
$("#button1").click(
function(){
process();
$('#result2').collapse('show');
return false;
}
);
$("#button2").click(
function(){
process2();
$('#result3').collapse('show');
return false;
}
);
$("#button3").click(
function(){
process3();
$('#result4').collapse('show');
return false;
}
);
$("#button_faucet").click(
function(){
window.open(
"http://faucet-01.symboldev.network/?recipient=" + alice.address.address + "&amount=200",
"_blank"
);
return false;
}
);
});</script>
</body>
</html>