-
Notifications
You must be signed in to change notification settings - Fork 411
/
BitcoinProcessor.sol
49 lines (42 loc) · 1.98 KB
/
BitcoinProcessor.sol
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
/*
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
See the LICENSE file in https://github.com/ethereum/btcrelay for further details.
Example contract that can process Bitcoin transactions relayed to it via
BTC Relay. This stores the Bitcoin transaction hash and the Ethereum block
number (so people running the same example with the same Bitcoin transaction
can get an indication that the storage was indeed updated).
*/
contract BitcoinProcessor {
uint256 public lastTxHash;
uint256 public ethBlock;
address private _trustedBTCRelay;
function BitcoinProcessor(address trustedBTCRelay) {
_trustedBTCRelay = trustedBTCRelay;
}
// processTransaction should avoid returning the same
// value as ERR_RELAY_VERIFY (in constants.se) to avoid confusing callers
//
// this exact function signature is required as it has to match
// the signature specified in BTCRelay (otherwise BTCRelay will not call it)
function processTransaction(bytes txn, uint256 txHash) returns (int256) {
log0("processTransaction called");
// only allow trustedBTCRelay, otherwise anyone can provide a fake txn
if (msg.sender == _trustedBTCRelay) {
log1("processTransaction txHash, ", bytes32(txHash));
ethBlock = block.number;
lastTxHash = txHash;
// parse & do whatever with txn
// For example, you should probably check if txHash has already
// been processed, to prevent replay attacks.
return 1;
}
log0("processTransaction failed");
return 0;
}
}