mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-26 21:42:48 +01:00
DLC code snippet clarification (#1393)
* 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:
parent
13a7980fb1
commit
c2c1c20518
1 changed files with 13 additions and 3 deletions
|
@ -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)
|
||||
```
|
||||
|
|
Loading…
Add table
Reference in a new issue