forked from unwriter/datapay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
composer.html
156 lines (156 loc) · 3.87 KB
/
composer.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
<html>
<head>
<style>
html {
height: 100%;
width: 100%;
overflow: hidden;
}
body {
height: 100%;
width: 100%;
overflow: auto;
display: flex;
margin: 0;
}
.hidden {
display: none;
}
.col {
flex-grow: 1;
position: relative;
display: flex;
flex-direction: column;
}
.header {
padding: 5px;
font-size: 12px;
font-family: Menlo, monaco, Courier;
text-align: center;
background: black;
color: white;
}
textarea {
font-size: 12px;
font-family: Menlo, monaco, Courier;
padding: 20px;
outline: none;
background: #2a2a2a;
color: rgba(255,255,255,0.8);
border: none;
width: 100%;
height: 100%;
}
#send {
position: fixed;
right: 30px;
bottom: 30px;
padding: 10px 20px;
font-family: Menlo, monaco, Courier;
background: gold;
font-size: 12px;
color: black;
text-decoration: none;
}
#sent {
position: fixed;
right: 30px;
bottom: 30px;
background: black;
color: gold;
padding: 10px 30px;
}
#sent a {
text-decoration: none;
}
#how {
font-size: 12px;
font-family: Menlo, monaco, Courier;
position: fixed;
bottom: 30px;
left: 30px;
background: black;
color: gold;
padding: 10px 30px;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://unpkg.com/[email protected]/dist/datapay.min.js"></script>
<script>
var endpoint = "https://api.bitindex.network/api/tx/send";
document.addEventListener("DOMContentLoaded", function(event) {
var dslEl = document.querySelector("#dsl");
var txEl = document.querySelector("#tx");
var hexEl = document.querySelector("#hex");
var sendEl = document.querySelector("#send");
var howEl = document.querySelector("#how");
dslEl.oninput = function(e) {
update(e.target.value)
}
howEl.onclick = function(e) {
alert("The first column is where you declaratively describe your transaction (See datapay documentation). The second column is where the generated transaction is displayed. The third column displays the actual hex encoded string that can be broadcasted to Bitcoin SV network. The default transaction description is just a simple data-only OP_RETURN transaction which only spends 300 satoshi transaction fee and nothing more, but you can experiment with different options as well. WARNING: THIS ACTUALLY WORKS, SO HANDLE WITH CARE.")
return false;
}
var update = function(html) {
var h = html.replace(/\n/g, '');
datapay.build(JSON.parse(h), function(err, tx) {
txEl.value = JSON.stringify(tx.toObject(), null, 2);
hexEl.value = tx.toString()
})
}
sendEl.onclick = function(e) {
var t = hexEl.value;
var isvalid = new datapay.bsv.Transaction(t).verify();
if (isvalid) {
send(t)
}
return false;
}
update(dslEl.value)
})
var send = function(transaction) {
fetch(endpoint, {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: 'POST',
body: JSON.stringify({rawtx: transaction})
})
.then(function(res) {
return res.json();
})
.then(function(response) {
console.log(response);
document.querySelector("#sent").innerHTML = "<a href='https://api.bitindex.network/api/v2/tx/" + response.txid + "' target='_blank'>Success! Click to view Transaction</a>";
document.querySelector("#sent").className = "";
document.querySelector("#send").className = "hidden";
})
}
</script>
</head>
<body>
<div class='col'>
<div class='header'>Transaction Description</div>
<textarea id='dsl'>
{
"data": ["0x6d02", "post to memo.cash!"],
"pay": {
"key": ""
}
}
</textarea>
</div>
<div class='col'>
<div class='header'>Generated Transaction</div>
<textarea id='tx'></textarea>
</div>
<div class='col'>
<div class='header'>Hex Format</div>
<textarea id='hex'></textarea>
</div>
<a href='#' id='send'>Click to Broadcast Transaction ></a>
<div id='sent' class='hidden'></div>
<a id='how' href='#'>how does this work?</a>
</body>
</html>