1
0
Fork 0
mirror of https://github.com/bitcoin-s/bitcoin-s.git synced 2025-03-26 21:42:48 +01:00

DLC code snippet clarification ()

* Give the different outcome amounts a val for clarity in documentation, add a missing import, and change the hash being signed by the oracle to more descriptive of a specific event

* Fix missing amounts

* Clarify comment even more
This commit is contained in:
Chris Stewart 2020-05-06 16:47:21 -05:00 committed by GitHub
parent 13a7980fb1
commit c2c1c20518
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -52,16 +52,26 @@ Note: if you wish to setup your own oracle for testing, you can do so by pasting
import org.bitcoins.core.crypto._
import org.bitcoins.core.currency._
import org.bitcoins.crypto.CryptoUtil
import scodec.bits._
val privKey = ECPrivateKey.freshPrivateKey
val pubKey = privKey.publicKey
val kValue = ECPrivateKey.freshPrivateKey
val rValue = kValue.schnorrNonce
val winHash = CryptoUtil.sha256(ByteVector("WIN".getBytes)).flip
val loseHash = CryptoUtil.sha256(ByteVector("LOSE".getBytes)).flip
//the hash the oracle will sign when the bitcoin price is over $9,000
val winHash = CryptoUtil.sha256(ByteVector("BTC_OVER_9000".getBytes)).flip
//the hash the oracle with sign when the bitcoin price is under $9,000
val loseHash = CryptoUtil.sha256(ByteVector("BTC_UNDER_9000".getBytes)).flip
//the amounts received in the case the oracle signs hash of message "BTC_OVER_9000"
val amtReceivedOnWin = Satoshis(100000)
//the amount received in the case the oracle signs hash of message "BTC_UNDER_9000"
val amtReceivedOnLoss = Satoshis.zero
(pubKey.bytes ++ rValue.bytes).toHex
(winHash.bytes ++ Satoshis(100000).bytes ++ loseHash.bytes ++ Satoshis.zero.bytes).toHex
(winHash.bytes ++ amtReceivedOnWin.bytes ++ loseHash.bytes ++ amtReceivedOnLoss.bytes).toHex
privKey.schnorrSignWithNonce(winHash.bytes, kValue)
privKey.schnorrSignWithNonce(loseHash.bytes, kValue)
```