Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Lit stuff
lit
dlcoracle
lit-af
!cmd/lit-af
cmd/lit-af/lit-af
Expand Down
113 changes: 113 additions & 0 deletions cmd/lit-af/dlccmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ var contractCommand = &Command{
fmt.Sprintf("%-20s %s",
lnutil.White("settime"),
"Sets the settlement time of a contract"),
fmt.Sprintf("%-20s %s",
lnutil.White("setrefundtime"),
"Sets the refund time of a contract"),
fmt.Sprintf("%-20s %s",
lnutil.White("setdatafeed"),
"Sets the data feed to use, will fetch the R point"),
Expand All @@ -117,6 +120,9 @@ var contractCommand = &Command{
fmt.Sprintf("%-20s %s",
lnutil.White("setcointype"),
"Sets the cointype of a contract"),
fmt.Sprintf("%-20s %s",
lnutil.White("setfeeperbyte"),
"Sets the fee per byte for a contract"),
fmt.Sprintf("%-20s %s",
lnutil.White("offer"),
"Offer a draft contract to one of your peers"),
Expand Down Expand Up @@ -238,6 +244,23 @@ var setContractSettlementTimeCommand = &Command{
),
ShortDescription: "Sets the settlement time for the contract\n",
}


var setContractRefundTimeCommand = &Command{
Format: fmt.Sprintf("%s%s\n", lnutil.White("dlc contract settime"),
lnutil.ReqColor("cid", "time")),
Description: fmt.Sprintf("%s\n%s\n%s\n",
"Sets the refund time for the contract",
fmt.Sprintf("%-10s %s",
lnutil.White("cid"),
"The ID of the contract"),
fmt.Sprintf("%-10s %s",
lnutil.White("time"),
"The refund time (unix timestamp)"),
),
ShortDescription: "Sets the settlement time for the contract\n",
}

var setContractFundingCommand = &Command{
Format: fmt.Sprintf("%s%s\n", lnutil.White("dlc contract setfunding"),
lnutil.ReqColor("cid", "ourAmount", "theirAmount")),
Expand Down Expand Up @@ -289,6 +312,20 @@ var setContractCoinTypeCommand = &Command{
),
ShortDescription: "Sets the coin type to use for the contract\n",
}
var setContractFeePerByteCommand = &Command{
Format: fmt.Sprintf("%s%s\n", lnutil.White("dlc contract setfeeperbyte"),
lnutil.ReqColor("cid", "feeperbyte")),
Description: fmt.Sprintf("%s\n%s\n%s\n",
"Sets the fee per byte to use for the contract",
fmt.Sprintf("%-10s %s",
lnutil.White("cid"),
"The ID of the contract"),
fmt.Sprintf("%-10s %s",
lnutil.White("cointype"),
"The fee per byte in satoshi to use for the contract"),
),
ShortDescription: "Sets the fee per byte in satoshi to use for the contract\n",
}
var declineContractCommand = &Command{
Format: fmt.Sprintf("%s%s\n", lnutil.White("dlc contract decline"),
lnutil.ReqColor("cid")),
Expand Down Expand Up @@ -492,6 +529,10 @@ func (lc *litAfClient) DlcContract(textArgs []string) error {
return lc.DlcSetContractSettlementTime(textArgs)
}

if cmd == "setrefundtime" {
return lc.DlcSetContractRefundTime(textArgs)
}

if cmd == "setfunding" {
return lc.DlcSetContractFunding(textArgs)
}
Expand All @@ -504,6 +545,10 @@ func (lc *litAfClient) DlcContract(textArgs []string) error {
return lc.DlcSetContractCoinType(textArgs)
}

if cmd == "setfeeperbyte" {
return lc.DlcSetContractFeePerByte(textArgs)
}

if cmd == "offer" {
return lc.DlcOfferContract(textArgs)
}
Expand Down Expand Up @@ -737,6 +782,38 @@ func (lc *litAfClient) DlcSetContractSettlementTime(textArgs []string) error {
return nil
}

func (lc *litAfClient) DlcSetContractRefundTime(textArgs []string) error {
stopEx, err := CheckHelpCommand(setContractRefundTimeCommand, textArgs, 2)
if err != nil || stopEx {
return err
}

args := new(litrpc.SetContractSettlementTimeArgs)
reply := new(litrpc.SetContractSettlementTimeReply)

cIdx, err := strconv.ParseUint(textArgs[0], 10, 64)
if err != nil {
return err
}
time, err := strconv.ParseUint(textArgs[1], 10, 64)
if err != nil {
return err
}
args.CIdx = cIdx
args.Time = time

err = lc.Call("LitRPC.SetContractRefundTime", args, reply)
if err != nil {
return err
}

fmt.Fprint(color.Output, "Refund time set successfully\n")

return nil
}



func (lc *litAfClient) DlcSetContractFunding(textArgs []string) error {
stopEx, err := CheckHelpCommand(setContractFundingCommand, textArgs, 3)
if err != nil || stopEx {
Expand Down Expand Up @@ -803,6 +880,40 @@ func (lc *litAfClient) DlcSetContractCoinType(textArgs []string) error {
return nil
}


func (lc *litAfClient) DlcSetContractFeePerByte(textArgs []string) error {
stopEx, err := CheckHelpCommand(setContractFeePerByteCommand, textArgs, 2)
if err != nil || stopEx {
return err
}

args := new(litrpc.SetContractFeePerByteArgs)
reply := new(litrpc.SetContractFeePerByteReply)

cIdx, err := strconv.ParseUint(textArgs[0], 10, 64)
if err != nil {
return err
}
feeperbyte, err := strconv.ParseUint(textArgs[1], 10, 64)
if err != nil {
return err
}

args.CIdx = cIdx
args.FeePerByte = uint32(feeperbyte)

err = lc.Call("LitRPC.SetContractFeePerByte", args, reply)
if err != nil {
return err
}

fmt.Fprint(color.Output, "Fee per byte set successfully\n")

return nil
}



func (lc *litAfClient) DlcSetContractDivision(textArgs []string) error {
stopEx, err := CheckHelpCommand(setContractDivisionCommand, textArgs, 3)
if err != nil || stopEx {
Expand Down Expand Up @@ -969,6 +1080,8 @@ func PrintContract(c *lnutil.DlcContract) {
lnutil.White("Funded by peer"), c.TheirFundingAmount)
fmt.Fprintf(color.Output, "%-30s : %d\n",
lnutil.White("Coin type"), c.CoinType)
fmt.Fprintf(color.Output, "%-30s : %d\n",
lnutil.White("Fee per byte"), c.FeePerByte)

peer := "None"
if c.PeerIdx > 0 {
Expand Down
50 changes: 40 additions & 10 deletions dlc/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

const COINTYPE_NOT_SET = ^uint32(0) // Max Uint
const FEEPERBYTE_NOT_SET = ^uint32(0) // Max Uint

// AddContract starts a new draft contract
func (mgr *DlcManager) AddContract() (*lnutil.DlcContract, error) {
Expand All @@ -15,6 +16,7 @@ func (mgr *DlcManager) AddContract() (*lnutil.DlcContract, error) {
c := new(lnutil.DlcContract)
c.Status = lnutil.ContractStatusDraft
c.CoinType = COINTYPE_NOT_SET
c.FeePerByte = FEEPERBYTE_NOT_SET
err = mgr.SaveContract(c)
if err != nil {
return nil, err
Expand All @@ -32,24 +34,18 @@ func (mgr *DlcManager) SetContractOracle(cIdx, oIdx uint64) error {
if err != nil {
return err
}

if c.Status != lnutil.ContractStatusDraft {
return fmt.Errorf("You cannot change or set the oracle unless the" +
" contract is in Draft state")
}

o, err := mgr.LoadOracle(oIdx)
if err != nil {
return err
}

c.OracleA = o.A

// Reset the R point when changing the oracle
c.OracleR = [33]byte{}

mgr.SaveContract(c)

return nil
}

Expand All @@ -60,22 +56,36 @@ func (mgr *DlcManager) SetContractSettlementTime(cIdx, time uint64) error {
if err != nil {
return err
}

if c.Status != lnutil.ContractStatusDraft {
return fmt.Errorf("You cannot change or set the settlement time" +
" unless the contract is in Draft state")
}

c.OracleTimestamp = time

// Reset the R point
c.OracleR = [33]byte{}

mgr.SaveContract(c)
return nil
}


// SetContractRefundTime. If until this time Oracle does not publish the data,
// then either party can publish a RefundTransaction
func (mgr *DlcManager) SetContractRefundTime(cIdx, time uint64) error {
c, err := mgr.LoadContract(cIdx)
if err != nil {
return err
}
if c.Status != lnutil.ContractStatusDraft {
return fmt.Errorf("You cannot change or set the settlement time" +
" unless the contract is in Draft state")
}
c.RefundTimestamp = time
mgr.SaveContract(c)
return nil
}



// SetContractDatafeed will automatically fetch the R-point from the REST API,
// if an oracle is imported from a REST API. You need to set the settlement time
// first, because the R point is a key unique for the time and feed
Expand Down Expand Up @@ -244,3 +254,23 @@ func (mgr *DlcManager) SetContractCoinType(cIdx uint64, cointype uint32) error {

return nil
}


//SetContractFeePerByte sets the fee per byte for a particular contract
func (mgr *DlcManager) SetContractFeePerByte(cIdx uint64, feeperbyte uint32) error {
c, err := mgr.LoadContract(cIdx)
if err != nil {
return err
}

if c.Status != lnutil.ContractStatusDraft {
return fmt.Errorf("You cannot change or set the fee per byte unless" +
" the contract is in Draft state")
}

c.FeePerByte = feeperbyte

mgr.SaveContract(c)

return nil
}
7 changes: 7 additions & 0 deletions docs/execute-dlc-litaf.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ Next, we configure the timestamp at which the contract will settle. This is a ti
dlc contract settime 1 1528848000
```

Now we have to configure refund timestamp after which the refund transaction becomes valid.

```
dlc contract setrefundtime 1 1528848000
```
In this case the refund transaction becomes valid at the same time.

Then, we configure the R-point for the contract, as mentioned earlier this is the public key to the one-time signing key used by the oracle to sign the value it will publish.

```
Expand Down
Loading