Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
185 changes: 183 additions & 2 deletions cmd/lit-af/dlccmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strconv"
"strings"
"time"
"errors"

"github.com/fatih/color"
"github.com/mit-dci/lit/litrpc"
Expand Down Expand Up @@ -102,6 +103,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 +121,11 @@ var contractCommand = &Command{
fmt.Sprintf("%-20s %s",
lnutil.White("setcointype"),
"Sets the cointype of a contract"),
fmt.Sprintf("%-20s %s",
lnutil.White("setfeeperbyte"),
fmt.Sprintf("%-20s %s",
lnutil.White("setoraclesnumber"),
"Sets the oracles number 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 +247,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 +315,36 @@ 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("feeperbyte"),
"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 setContractOraclesNumberCommand = &Command{
Format: fmt.Sprintf("%s%s\n", lnutil.White("dlc contract setoraclesnumber"),
lnutil.ReqColor("cid", "oraclesnumber")),
Description: fmt.Sprintf("%s\n%s\n%s\n",
"Sets the oracles number to use for the contract",
fmt.Sprintf("%-10s %s",
lnutil.White("cid"),
"The ID of the contract"),
fmt.Sprintf("%-10s %s",
lnutil.White("oraclesnumber"),
"The oracles number to use for the contract"),
),
ShortDescription: "Sets a number of oracles required 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 +548,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 +564,14 @@ func (lc *litAfClient) DlcContract(textArgs []string) error {
return lc.DlcSetContractCoinType(textArgs)
}

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

if cmd == "setoraclesnumber" {
return lc.DlcSetContractOraclesNumber(textArgs)
}

if cmd == "offer" {
return lc.DlcOfferContract(textArgs)
}
Expand Down Expand Up @@ -737,6 +805,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 +903,79 @@ 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) DlcSetContractOraclesNumber(textArgs []string) error {
stopEx, err := CheckHelpCommand(setContractOraclesNumberCommand, textArgs, 2)
if err != nil || stopEx {
return err
}

args := new(litrpc.SetContractOraclesNumberArgs)
reply := new(litrpc.SetContractOraclesNumberReply)

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

if OraclesNumber > 1 {
return errors.New("Multiple oracles supported only from RPC cals.")
}

args.CIdx = cIdx
args.OraclesNumber = uint32(OraclesNumber)

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

fmt.Fprint(color.Output, "SetContractOraclesNumber 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 @@ -956,19 +1129,27 @@ func PrintContract(c *lnutil.DlcContract) {
fmt.Fprintf(color.Output, "%-30s : %d\n", lnutil.White("Index"), c.Idx)
fmt.Fprintf(color.Output, "%-30s : [%x...%x...%x]\n",
lnutil.White("Oracle public key"),
c.OracleA[:2], c.OracleA[15:16], c.OracleA[31:])
c.OracleA[0][:2], c.OracleA[0][15:16], c.OracleA[0][31:])
fmt.Fprintf(color.Output, "%-30s : [%x...%x...%x]\n",
lnutil.White("Oracle R-point"), c.OracleR[:2],
c.OracleR[15:16], c.OracleR[31:])
c.OracleR[0][15:16], c.OracleR[0][31:])
fmt.Fprintf(color.Output, "%-30s : %s\n",
lnutil.White("Settlement time"),
time.Unix(int64(c.OracleTimestamp), 0).UTC().Format(time.UnixDate))
fmt.Fprintf(color.Output, "%-30s : %s\n",
lnutil.White("Refund time"),
time.Unix(int64(c.RefundTimestamp), 0).UTC().Format(time.UnixDate))
fmt.Fprintf(color.Output, "%-30s : %d\n",
lnutil.White("Funded by us"), c.OurFundingAmount)
fmt.Fprintf(color.Output, "%-30s : %d\n",
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)
fmt.Fprintf(color.Output, "%-30s : %d\n",
lnutil.White("Oracles number"), c.OraclesNumber)


peer := "None"
if c.PeerIdx > 0 {
Expand Down
1 change: 1 addition & 0 deletions consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ const (
QcStateFee = 10 // fixqcstatefee
DefaultLockTime = 500 //default lock time
DlcSettlementTxFee = 1000
MaxOraclesNumber = 8
)
Loading