Skip to content

Commit 78b816a

Browse files
committed
add support for btcrelay's validation fees
1 parent 93d2181 commit 78b816a

16 files changed

+1174
-326
lines changed

Gruntfile.js

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ module.exports = function(grunt) {
1010
"lib/keccak.js": "src/keccak.js",
1111
"lib/btc-swap.js": "src/btc-swap.js",
1212
"lib/abi/btc-swap.js": "src/abi/btc-swap.js",
13-
"lib/abi/debug.js": "src/abi/debug.js",
1413
"lib/abi/btcrelay.js": "src/abi/btcrelay.js"
1514
}
1615
}

README.md

+14-7
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ first parameter and the Ethereum transaction hash as second parameter. The
4242
`completed` callback gets fired when the transaction is mined and returns the
4343
reserved ticket object.
4444

45-
#### `claimTicket(ticketId, txHex, txHash, txIndex, merkleSibling, txBlockHash, success, completed, failure)`
45+
#### `claimTicket(ticketId, txHex, txHash, txIndex, merkleSibling, txBlockHash,
46+
feeWei, success, completed, failure)`
4647
Claim a ticket with ID `ticketId`, with the signed BTC transaction hex `txHex`,
4748
the BTC transaction hash `txHash`, BTC transaction index `txIndex`, BTC merkle
48-
siblings `merkleSibling` and BTC block hash `txBlockHash`. The `success`
49-
callback gets fired when the Ethereum transaction is sent and returns the
50-
Ethereum transaction hash. The `completed` callback gets fired when the
51-
transaction is mined and returns the ticket ID.
49+
siblings `merkleSibling` and BTC block hash `txBlockHash`. `feeWei` can be
50+
obtained by calling `getFeeAmount(txBlockHash)` and will be the transaction's
51+
value if it's above zero. The `success` callback gets fired when the Ethereum
52+
transaction is sent and returns the Ethereum transaction hash. The `completed`
53+
callback gets fired when the transaction is mined and returns the ticket ID.
5254

5355
#### `cancelTicket(ticketId, success, failure)`
5456
Cancel a ticket with `ticketId`, if the ticket is still reservable and by
@@ -120,10 +122,15 @@ Query the [btcrelay](https://github.com/ethereum/btcrelay) contract for its last
120122
stored BTC block number. The `success` callback gets fired on a successful call
121123
and returns the block number of the latest block.
122124

123-
#### `storeBlockHeader(blockHash, success, failure)`
125+
#### `getFeeAmount(blockHash, success, failure)`
126+
Get the fee from [btcrelay](https://github.com/ethereum/btcrelay) to validate a
127+
transaction in a given `blockHash`. The `success` callback gets fired on a
128+
successful call and returns the fee amount in wei.
129+
130+
#### `storeBlockWithFee(blockHash, feeWei, success, failure)`
124131
Query the [blockr](https://blockr.io) API for the raw block data of a block
125132
with hash `blockHash`, generate the BTC block header from that data, call the
126-
`storeBlockHeader` method of [btcrelay](https://github.com/ethereum/btcrelay)
133+
`storeBlockWithFee` method of [btcrelay](https://github.com/ethereum/btcrelay)
127134
and send an Ethereum transaction for that same method if successful, effectively
128135
storing the block header. The `success` callback gets fired when the transaction
129136
is mined and returns the BTC block number for which the block header was stored.

contracts/btc-swap.se

+3-7
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ macro CLAIM_FAIL_TX_ENCODING: -27
4343

4444
# Events
4545
event ticketEvent(ticketId:indexed, rval)
46-
47-
# TODO testing only
48-
event claimSuccess(btcAddr, numSatoshi, ethAddr, satoshiIn2ndOutput)
46+
event claimSuccess(btcAddr, numSatoshi, ethAddr, satoshiIn2ndOutput, feeWei)
4947

5048
# Macros
5149

@@ -239,8 +237,7 @@ def claimTicket(ticketId, txStr:str, txHash, txIndex, sibling:arr, txBlockHash):
239237
log(type=ticketEvent, ticketId, CLAIM_FAIL_WRONG_BTC_ADDR)
240238
return(CLAIM_FAIL_WRONG_BTC_ADDR)
241239

242-
243-
if self.trustedBtcRelay.verifyTx(txHash, txIndex, sibling, txBlockHash):
240+
if self.trustedBtcRelay.verifyTx(txHash, txIndex, sibling, txBlockHash, value=msg.value):
244241

245242
satoshiIn2ndOutput = outputData[2]
246243

@@ -257,8 +254,7 @@ def claimTicket(ticketId, txStr:str, txHash, txIndex, sibling:arr, txBlockHash):
257254

258255
deleteTicket(ticketId)
259256

260-
# TODO for testing only; remove when deploying
261-
log(type=claimSuccess, addrBtcWasSentTo, numSatoshi, ethAddr, satoshiIn2ndOutput)
257+
log(type=claimSuccess, addrBtcWasSentTo, numSatoshi, ethAddr, satoshiIn2ndOutput, msg.value)
262258

263259
return(ticketId)
264260
else:

contracts/btc-swap.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# Private testnet relay: 0x3056d0b2379c86e6be6771c34f39f5affb65d855
1212
# ConsenSys testnet relay: 0x2fd4f3ae10608cd6192339e72d4f6a0c182dee22
1313
- set:
14-
BtcRelay: "0xa9eb7eec49f39a3030baacc95111fb94192be354"
14+
BtcRelay: "0xd34e752661c770ee2eb078326ed7a2a09acff135"
1515
-
1616
deploy:
1717
BtcSwap:

contracts/tests/test_btc-swap.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,11 @@ def testAnyClaimMustStillBeValidTx(self):
408408

409409
def assertClaimSuccessLogs(self, eventArr, satoshiOutputOne, btcAddr, ethAddr, satoshiOutputTwo, ticketId):
410410
assert eventArr[1] == {
411-
'_event_type': 'claimSuccess', 'numSatoshi': satoshiOutputOne,
411+
'_event_type': 'claimSuccess',
412+
'numSatoshi': satoshiOutputOne,
412413
'btcAddr': btcAddr,
413414
'ethAddr': ethAddr,
415+
'feeWei': 0,
414416
'satoshiIn2ndOutput': satoshiOutputTwo
415417
}
416418
eventArr.pop()

lib/abi/btc-swap.js

+158-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)