-
Notifications
You must be signed in to change notification settings - Fork 1
/
bcat-recovery.js
63 lines (47 loc) · 1.47 KB
/
bcat-recovery.js
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
const button = document.querySelector('#prepareButton');
button.addEventListener('click', prepareTransaction);
function prepareTransaction(e) {
e.preventDefault();
const fileName = document.querySelector('#fileName').value || ' ';
const mimeType = document.querySelector('#mimeType').value || ' ';
const encoding = document.querySelector('#encoding').value || ' ';
const txIdTextArea = document.querySelector('#txIds').value;
const txIds = txIdTextArea.match(/[0-9A-Fa-f]{64}/g);
console.log(txIds);
if (!txIds) {
alert(`No transaction ids entered`);
return;
}
const script = [
'15DHFxWZJT58f9nhyGnsRBqrgwK4W6h4Up',
' ',
mimeType,
encoding,
fileName,
' ',
...txIds.map(txId => bsv.deps.Buffer.from(txId, 'hex'))
]
const asm = bsv.Script.buildSafeDataOut(script).toASM();
const moneyButtonDiv = document.querySelector('#bcat-money-button');
moneyButton.render(moneyButtonDiv, {
label: "Send",
clientIdentifier: "3fb24dea420791729b4d9b39703c6339",
type: "buy",
outputs: [{
script: asm,
amount: 0,
currency: 'BSV'
}],
onPayment: onPayment,
onError: onError
});
}
function onPayment(arg) {
console.log(`Payment successful, txid: ${arg.txid}`);
const pTxId = document.querySelector('#txId');
pTxId.innerHTML = `<a href="https://bico.media/${arg.txid}" target='_blank'>${arg.txid}</a>`;
}
function onError(arg) {
console.log('Payment error', arg);
alert('Payment error');
}