Skip to content

Latest commit

 

History

History
 
 

sample

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

rust-dlc sample

Example of combining the various components of the rust-dlc library together with the custom message handler of rust-lightning to enable networked communication.

Originally based on the code from the ldk sample.

Example configurations and contract input are available in the examples folder.

Quick run

To give a quick try to this sample, run the following set of commands (assuming that the working directory is the one in which this readme is located and that docker is available on your machine):

../scripts/start_node.sh
../scripts/create_wallets.sh
cargo run ./examples/configurations/alice.yml

In a different terminal:

cargo run ./examples/configurations/bob.yml

From the second instance (Bob), type:

offercontract 02c84f8e151590e718d22e528c55f14c0042c66e68c3f793d7b3b8bf5ae630c648@127.0.0.1:9000 ./examples/contracts/numerical_contract_input.json

Replacing the public key by the one that was displayed when starting the first instance.

From the first instance (Alice), type:

listoffers

You should see the id of the contract that was offered by Bob. A JSON file with contract information should also have been saved in Alice's data folder (./dlc_sample_alice/offers/xxx.json).

Alice can now accept the offer by typing:

acceptoffer xxxxx

replacing xxxxx with the contract id that was previously displayed.

This will make Alice's instance send an accept message to Bob. In Bob's instance, typing listcontracts will trigger the processing of the message, and you should see that the contract will be in Signed, as Bob will automatically reply to Alice with a Sign message.

Typing the same command in Alice's instance will make Alice broadcast the fund transaction.

Now in yet another terminal (still from the same location) run:

../scripts/generate_blocks.sh

This will generate some blocks so that the fund transaction is confirmed.

Typing listcontracts in either instance should now show the contract as Confirmed.

Once the maturity of the contract is reached, typing listcontracts once more will retrieve the attestation from the oracle and close the contract, displaying the event outcome (in decomposed binary format) and the profit and loss for the given instance.