-
Notifications
You must be signed in to change notification settings - Fork 20
/
revoke-ssc
executable file
·52 lines (43 loc) · 1.44 KB
/
revoke-ssc
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
#!/usr/bin/env coffee
{ log } = require 'lightsaber'
fs = require 'fs'
bitcore = require 'bitcore'
Insight = require('bitcore-explorers').Insight
ClaimData = require './src/ClaimData.coffee'
class RevokeCert
domainName: "www.mydomain.com"
returnAddr: "mwmabpJVisvti3WEP5vhFRtn3yqHRD9KNP" # specifically for testnet faucet
network: bitcore.Networks.testnet
constructor: (dataFile)->
@data = ClaimData.load(dataFile)
@insight = new Insight 'https://test-insight.bitpay.com', @network
@privateKey = @data.destinationPK
unspentTxns: (callback)->
address = @privateKey.toAddress(@network)
@insight.getUnspentUtxos address, callback
createTxn: (utxos)->
total = utxos[0].satoshis
fee = 10000
new bitcore.Transaction()
.from utxos[0]
.to(@returnAddr, (total-fee))
.sign(@privateKey)
broadcastTxn: (txn, callback)->
@insight.broadcast txn, callback
domainName = "www.mydomain.com"
rev = new RevokeCert("tmp/certs/#{domainName}.json")
log "Emptying claim address #{rev.data.destinationAddress()}"
rev.unspentTxns (error, utxos)->
if error
console.error error
else
if utxos.length == 0
log "No unspent transactions (address already empty)."
else
txn = rev.createTxn(utxos)
log "Broadcasting revocation transaction: #{txn.serialize()}"
rev.broadcastTxn txn, (err, txnid)->
if err
console.error err
else
log "Transaction ID: #{txnid}"