Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace int data type #41

Merged
merged 1 commit into from
Mar 9, 2021
Merged
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
30 changes: 15 additions & 15 deletions boltz/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ type GetVersionResponse struct {
}

type symbolMinerFees struct {
Normal int `json:"normal"`
Normal uint64 `json:"normal"`
Reverse struct {
Lockup int `json:"lockup"`
Claim int `json:"claim"`
Lockup uint64 `json:"lockup"`
Claim uint64 `json:"claim"`
} `json:"reverse"`
}

Expand All @@ -33,8 +33,8 @@ type GetPairsResponse struct {
Pairs map[string]struct {
Rate float32 `json:"rate"`
Limits struct {
Maximal int `json:"maximal"`
Minimal int `json:"minimal"`
Maximal uint64 `json:"maximal"`
Minimal uint64 `json:"minimal"`
} `json:"limits"`
Fees struct {
Percentage float32 `json:"percentage"`
Expand All @@ -61,7 +61,7 @@ type SwapStatusResponse struct {
Status string `json:"status"`
Channel struct {
FundingTransactionId string `json:"fundingTransactionId"`
FundingTransactionVout int `json:"fundingTransactionVout"`
FundingTransactionVout uint32 `json:"fundingTransactionVout"`
} `json:"channel"`
Transaction struct {
Id string `json:"id"`
Expand Down Expand Up @@ -109,8 +109,8 @@ type CreateSwapResponse struct {
Address string `json:"address"`
RedeemScript string `json:"redeemScript"`
AcceptZeroConf bool `json:"acceptZeroConf"`
ExpectedAmount int `json:"expectedAmount"`
TimeoutBlockHeight int `json:"timeoutBlockHeight"`
ExpectedAmount uint64 `json:"expectedAmount"`
TimeoutBlockHeight uint32 `json:"timeoutBlockHeight"`

Error string `json:"error"`
}
Expand All @@ -120,9 +120,9 @@ type SwapRatesRequest struct {
}

type SwapRatesResponse struct {
OnchainAmount int `json:"onchainAmount"`
OnchainAmount uint64 `json:"onchainAmount"`
SubmarineSwap struct {
InvoiceAmount int `json:"invoiceAmount"`
InvoiceAmount uint64 `json:"invoiceAmount"`
} `json:"submarineSwap"`

Error string `json:"error"`
Expand All @@ -141,7 +141,7 @@ type CreateReverseSwapRequest struct {
Type string `json:"type"`
PairId string `json:"pairId"`
OrderSide string `json:"orderSide"`
InvoiceAmount int `json:"invoiceAmount"`
InvoiceAmount uint64 `json:"invoiceAmount"`
PreimageHash string `json:"preimageHash"`
ClaimPublicKey string `json:"claimPublicKey"`
}
Expand All @@ -166,10 +166,10 @@ type CreateChannelCreationRequest struct {
type CreateReverseSwapResponse struct {
Id string `json:"id"`
Invoice string `json:"invoice"`
OnchainAmount int `json:"onchainAmount"`
OnchainAmount uint64 `json:"onchainAmount"`
RedeemScript string `json:"redeemScript"`
LockupAddress string `json:"lockupAddress"`
TimeoutBlockHeight int `json:"TimeoutBlockHeight"`
TimeoutBlockHeight uint32 `json:"TimeoutBlockHeight"`

Error string `json:"error"`
}
Expand All @@ -192,8 +192,8 @@ func (boltz *Boltz) GetPairs() (*GetPairsResponse, error) {
return &response, err
}

func (boltz *Boltz) GetFeeEstimation() (*map[string]int, error) {
var response map[string]int
func (boltz *Boltz) GetFeeEstimation() (*map[string]uint64, error) {
var response map[string]uint64
err := boltz.sendGetRequest("/getfeeestimation", &response)

return &response, err
Expand Down
6 changes: 3 additions & 3 deletions boltz/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var invalidRedeemScript = errors.New("invalid redeem script")

func CheckSwapScript(redeemScript, preimageHash []byte, refundKey *btcec.PrivateKey, timeoutBlockHeight int) error {
func CheckSwapScript(redeemScript, preimageHash []byte, refundKey *btcec.PrivateKey, timeoutBlockHeight uint32) error {
disassembledScript, err := txscript.DisasmString(redeemScript)

if err != nil {
Expand Down Expand Up @@ -40,7 +40,7 @@ func CheckSwapScript(redeemScript, preimageHash []byte, refundKey *btcec.Private
return nil
}

func CheckReverseSwapScript(redeemScript, preimageHash []byte, claimKey *btcec.PrivateKey, timeoutBlockHeight int) error {
func CheckReverseSwapScript(redeemScript, preimageHash []byte, claimKey *btcec.PrivateKey, timeoutBlockHeight uint32) error {
disassembledScript, err := txscript.DisasmString(redeemScript)

if err != nil {
Expand Down Expand Up @@ -73,7 +73,7 @@ func CheckReverseSwapScript(redeemScript, preimageHash []byte, claimKey *btcec.P
return nil
}

func formatHeight(height int) string {
func formatHeight(height uint32) string {
test, _ := txscript.NewScriptBuilder().AddInt64(int64(height)).Script()
return hex.EncodeToString(test[1:])
}
4 changes: 2 additions & 2 deletions boltz/scripts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestCheckSwapScript(t *testing.T) {
key, _ := hex.DecodeString("88c4ac1e6d099ea63eda4a0ae4863420dbca9aa1bce536aa63d46db28c7b780e")
refundKey, _ := btcec.PrivKeyFromBytes(btcec.S256(), key)

timeoutBlockHeight := 248
var timeoutBlockHeight uint32 = 248

assert.Nil(t, CheckSwapScript(redeemScript, preimageHash, refundKey, timeoutBlockHeight))

Expand All @@ -34,7 +34,7 @@ func TestCheckReverseSwapScript(t *testing.T) {
key, _ := hex.DecodeString("dddc90e33843662631fb8c3833c4743ffd8f00a94715735633bf178e62eb291c")
claimKey, _ := btcec.PrivKeyFromBytes(btcec.S256(), key)

timeoutBlockHeight := 248
var timeoutBlockHeight uint32 = 248

assert.Nil(t, CheckReverseSwapScript(redeemScript, preimageHash, claimKey, timeoutBlockHeight))

Expand Down
10 changes: 5 additions & 5 deletions database/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import (
type ChannelCreation struct {
SwapId string
Status boltz.ChannelState
InboundLiquidity int
InboundLiquidity uint32
Private bool
FundingTransactionId string
FundingTransactionVout int
FundingTransactionVout uint32
}

type ChannelCreationSerialized struct {
SwapId string
Status string
InboundLiquidity int
InboundLiquidity uint32
Private bool
FundingTransactionId string
FundingTransactionVout int
FundingTransactionVout uint32
}

func (channelCreation *ChannelCreation) Serialize() ChannelCreationSerialized {
Expand Down Expand Up @@ -103,7 +103,7 @@ func (database *Database) CreateChannelCreation(channelCreation ChannelCreation)
return statement.Close()
}

func (database *Database) SetChannelFunding(channelCreation *ChannelCreation, fundingTransactionId string, fundingTransactionVout int) error {
func (database *Database) SetChannelFunding(channelCreation *ChannelCreation, fundingTransactionId string, fundingTransactionVout uint32) error {
channelCreation.Status = boltz.ChannelAccepted
channelCreation.FundingTransactionId = fundingTransactionId
channelCreation.FundingTransactionVout = fundingTransactionVout
Expand Down
8 changes: 4 additions & 4 deletions database/reverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type ReverseSwap struct {
RedeemScript []byte
Invoice string
ClaimAddress string
OnchainAmount int
TimeoutBlockHeight int
OnchainAmount uint64
TimeoutBlockHeight uint32
LockupTransactionId string
ClaimTransactionId string
}
Expand All @@ -38,8 +38,8 @@ type ReverseSwapSerialized struct {
RedeemScript string
Invoice string
ClaimAddress string
OnchainAmount int
TimeoutBlockHeight int
OnchainAmount uint64
TimeoutBlockHeight uint32
LockupTransactionId string
ClaimTransactionId string
}
Expand Down
10 changes: 5 additions & 5 deletions database/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type Swap struct {
RedeemScript []byte
Invoice string
Address string
ExpectedAmount int
TimoutBlockHeight int
ExpectedAmount uint64
TimoutBlockHeight uint32
LockupTransactionId string
RefundTransactionId string
}
Expand All @@ -36,8 +36,8 @@ type SwapSerialized struct {
RedeemScript string
Invoice string
Address string
ExpectedAmount int
TimeoutBlockHeight int
ExpectedAmount uint64
TimeoutBlockHeight uint32
LockupTransactionId string
RefundTransactionId string
}
Expand Down Expand Up @@ -177,7 +177,7 @@ func (database *Database) QueryPendingSwaps() ([]Swap, error) {
}

func (database *Database) QueryRefundableSwaps(currentBlockHeight uint32) ([]Swap, error) {
return database.querySwaps("SELECT * FROM swaps WHERE (state = '" + strconv.Itoa(int(boltzrpc.SwapState_PENDING)) + "' OR state = '"+ strconv.Itoa(int(boltzrpc.SwapState_SERVER_ERROR)) + "') AND timeoutBlockHeight <= " + strconv.FormatUint(uint64(currentBlockHeight), 10))
return database.querySwaps("SELECT * FROM swaps WHERE (state = '" + strconv.Itoa(int(boltzrpc.SwapState_PENDING)) + "' OR state = '" + strconv.Itoa(int(boltzrpc.SwapState_SERVER_ERROR)) + "') AND timeoutBlockHeight <= " + strconv.FormatUint(uint64(currentBlockHeight), 10))
}

func (database *Database) CreateSwap(swap Swap) error {
Expand Down
2 changes: 1 addition & 1 deletion nursery/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (nursery *Nursery) updateChannelCreationStatus(channelCreation *database.Ch
}
}

func calculateChannelCreationCapacity(invoiceAmount float64, inboundLiquidity int) int64 {
func calculateChannelCreationCapacity(invoiceAmount float64, inboundLiquidity uint32) int64 {
capacity := invoiceAmount / (1 - (float64(inboundLiquidity) / 100))
return int64(math.Floor(capacity))
}
10 changes: 5 additions & 5 deletions nursery/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (nursery *Nursery) handleSwapStatus(swap *database.Swap, channelCreation *d
return
}

logger.Info("Found output for Swap " + swap.Id + " of " + strconv.Itoa(swapRates.OnchainAmount) + " satoshis")
logger.Info("Found output for Swap " + swap.Id + " of " + strconv.FormatUint(swapRates.OnchainAmount, 10) + " satoshis")

lndInfo, err := nursery.lnd.GetInfo()

Expand All @@ -320,7 +320,7 @@ func (nursery *Nursery) handleSwapStatus(swap *database.Swap, channelCreation *d
return
}

logger.Info("Generated new invoice for Swap " + swap.Id + " for " + strconv.Itoa(swapRates.SubmarineSwap.InvoiceAmount) + " satoshis")
logger.Info("Generated new invoice for Swap " + swap.Id + " for " + strconv.FormatUint(swapRates.SubmarineSwap.InvoiceAmount, 10) + " satoshis")

_, err = nursery.boltz.SetInvoice(boltz.SetInvoiceRequest{
Id: swap.Id,
Expand Down Expand Up @@ -413,7 +413,7 @@ func (nursery *Nursery) handleSwapStatus(swap *database.Swap, channelCreation *d
}

if invoiceInfo.State != lnrpc.Invoice_SETTLED {
logger.Warning(swapType + " " + swap.Id + " was not actually settled. Refunding at block " + strconv.Itoa(swap.TimoutBlockHeight))
logger.Warning(swapType + " " + swap.Id + " was not actually settled. Refunding at block " + strconv.FormatUint(uint64(swap.TimoutBlockHeight), 10))
return
}

Expand All @@ -439,15 +439,15 @@ func (nursery *Nursery) handleSwapStatus(swap *database.Swap, channelCreation *d
}
}

func parseChannelPoint(channelPoint string) (string, int, error) {
func parseChannelPoint(channelPoint string) (string, uint32, error) {
split := strings.Split(channelPoint, ":")
vout, err := strconv.Atoi(split[1])

if err != nil {
return "", 0, err
}

return split[0], vout, nil
return split[0], uint32(vout), nil
}

func getSwapType(isChannelCreation bool) string {
Expand Down
8 changes: 4 additions & 4 deletions rpcserver/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (server *routedBoltzServer) Deposit(_ context.Context, request *boltzrpc.De
func (server *routedBoltzServer) CreateSwap(_ context.Context, request *boltzrpc.CreateSwapRequest) (*boltzrpc.CreateSwapResponse, error) {
logger.Info("Creating Swap for " + strconv.FormatInt(request.Amount, 10) + " satoshis")

invoice, err := server.lnd.AddInvoice(request.Amount, nil, 0, utils.GetSwapMemo(server.symbol))
invoice, err := server.lnd.AddInvoice(int64(request.Amount), nil, 0, utils.GetSwapMemo(server.symbol))

if err != nil {
return nil, handleError(err)
Expand Down Expand Up @@ -355,7 +355,7 @@ func (server *routedBoltzServer) CreateChannel(_ context.Context, request *boltz

invoice, err := server.lnd.AddHoldInvoice(
preimageHash,
request.Amount,
int64(request.Amount),
// TODO: query timeout block delta from API
utils.CalculateInvoiceExpiry(144, utils.GetBlockTime(server.symbol)),
"Channel Creation from "+server.symbol,
Expand Down Expand Up @@ -415,7 +415,7 @@ func (server *routedBoltzServer) CreateChannel(_ context.Context, request *boltz
channelCreation := database.ChannelCreation{
SwapId: response.Id,
Status: boltz.ChannelNone,
InboundLiquidity: int(inboundLiquidity),
InboundLiquidity: inboundLiquidity,
Private: request.Private,
FundingTransactionId: "",
FundingTransactionVout: 0,
Expand Down Expand Up @@ -499,7 +499,7 @@ func (server *routedBoltzServer) CreateReverseSwap(_ context.Context, request *b
Type: "reverseSubmarine",
PairId: server.symbol + "/" + server.symbol,
OrderSide: "buy",
InvoiceAmount: int(request.Amount),
InvoiceAmount: uint64(request.Amount),
PreimageHash: hex.EncodeToString(preimageHash),
ClaimPublicKey: hex.EncodeToString(publicKey.SerializeCompressed()),
})
Expand Down
8 changes: 4 additions & 4 deletions rpcserver/serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func serializeSwap(swap *database.Swap) *boltzrpc.SwapInfo {
Invoice: serializedSwap.Invoice,
LockupAddress: serializedSwap.Address,
ExpectedAmount: int64(serializedSwap.ExpectedAmount),
TimeoutBlockHeight: uint32(serializedSwap.TimeoutBlockHeight),
TimeoutBlockHeight: serializedSwap.TimeoutBlockHeight,
LockupTransactionId: serializedSwap.LockupTransactionId,
RefundTransactionId: serializedSwap.RefundTransactionId,
}
Expand All @@ -31,10 +31,10 @@ func serializeChannelCreation(channelCreation *database.ChannelCreation) *boltzr
return &boltzrpc.ChannelCreationInfo{
SwapId: serializedChannelCreation.SwapId,
Status: serializedChannelCreation.Status,
InboundLiquidity: uint32(serializedChannelCreation.InboundLiquidity),
InboundLiquidity: serializedChannelCreation.InboundLiquidity,
Private: serializedChannelCreation.Private,
FundingTransactionId: serializedChannelCreation.FundingTransactionId,
FundingTransactionVout: uint32(serializedChannelCreation.FundingTransactionVout),
FundingTransactionVout: serializedChannelCreation.FundingTransactionVout,
}
}

Expand All @@ -52,7 +52,7 @@ func serializeReverseSwap(reverseSwap *database.ReverseSwap) *boltzrpc.ReverseSw
Invoice: serializedReverseSwap.Invoice,
ClaimAddress: serializedReverseSwap.ClaimAddress,
OnchainAmount: int64(serializedReverseSwap.OnchainAmount),
TimeoutBlockHeight: uint32(serializedReverseSwap.TimeoutBlockHeight),
TimeoutBlockHeight: serializedReverseSwap.TimeoutBlockHeight,
LockupTransactionId: serializedReverseSwap.LockupTransactionId,
ClaimTransactionId: serializedReverseSwap.ClaimTransactionId,
}
Expand Down