Merge pull request #464 from intelliot/patch-3

Send a Conditionally-Held Escrow: update example
This commit is contained in:
Rome Reginelli
2018-10-24 13:00:29 -07:00
committed by GitHub

View File

@@ -10,14 +10,20 @@ XRP Ledger escrows require PREIMAGE-SHA-256 [Crypto-Conditions](https://tools.ie
Example JavaScript code for a random fulfillment and condition: Example JavaScript code for a random fulfillment and condition:
```js ```js
cc = require('five-bells-condition'); const cc = require('five-bells-condition')
const crypto = require('crypto')
const fulfillment_bytes = crypto.randomBytes(32); const preimageData = crypto.randomBytes(32)
const myFulfillment = new cc.PreimageSha256(); const myFulfillment = new cc.PreimageSha256()
myFulfillment.setPreimage(fulfillment_bytes); myFulfillment.setPreimage(preimageData)
console.log(myFulfillment.serializeBinary().toString('hex'));
const condition = myFulfillment.getConditionBinary().toString('hex').toUpperCase()
console.log('Condition:', condition)
// (Random hexadecimal, 72 chars in length) // (Random hexadecimal, 72 chars in length)
console.log(myFulfillment.getConditionBinary().toString('hex'));
// keep secret until you want to finish executing the held payment:
const fulfillment = myFulfillment.serializeBinary().toString('hex').toUpperCase()
console.log('Fulfillment:', fulfillment)
// (Random hexadecimal, 78 chars in length) // (Random hexadecimal, 78 chars in length)
``` ```
@@ -35,9 +41,9 @@ Example for setting a `CancelAfter` time of 24 hours in the future:
_JavaScript_ _JavaScript_
```js ```js
const rippleOffset = 946684800; const rippleOffset = 946684800
const CancelAfter = Math.floor(Date.now() / 1000) + (24*60*60) - rippleOffset; const CancelAfter = Math.floor(Date.now() / 1000) + (24*60*60) - rippleOffset
console.log(CancelAfter); console.log(CancelAfter)
// Example: 556927412 // Example: 556927412
``` ```