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

Supported x32 architecture. #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 0 additions & 3 deletions glightning/lightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,16 +417,13 @@ type Channel struct {
ShortChannelId string `json:"short_channel_id"`
IsPublic bool `json:"public"`
Satoshis uint64 `json:"satoshis"`
AmountMsat string `json:"amount_msat"`
MessageFlags uint `json:"message_flags"`
ChannelFlags uint `json:"channel_flags"`
IsActive bool `json:"active"`
LastUpdate uint `json:"last_update"`
BaseFeeMillisatoshi uint64 `json:"base_fee_millisatoshi"`
FeePerMillionth uint64 `json:"fee_per_millionth"`
Delay uint `json:"delay"`
HtlcMinimumMilliSatoshis string `json:"htlc_minimum_msat"`
HtlcMaximumMilliSatoshis string `json:"htlc_maximum_msat"`
}

// Get channel by {shortChanId}
Expand Down
8 changes: 6 additions & 2 deletions jrpc2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net"
"os"
"sync"
"math"
"sync/atomic"
"time"
)
Expand All @@ -23,7 +24,7 @@ import (
type Client struct {
requestQueue chan *Request
pending sync.Map // map[string]chan *RawResponse
requestCounter int64
requestCounter uint32
shutdown bool
timeout time.Duration
}
Expand Down Expand Up @@ -226,6 +227,9 @@ func handleReply(rawResp *RawResponse, resp interface{}) error {

// for now, use a counter as the id for requests
func (c *Client) NextId() *Id {
val := atomic.AddInt64(&c.requestCounter, 1)
if c.requestCounter == math.MaxUint32 {
atomic.StoreUint32(&c.requestCounter, 0)
}
val := atomic.AddUint32(&c.requestCounter, 1)
return NewIdAsInt(val)
}
10 changes: 5 additions & 5 deletions jrpc2/jsonrpc2.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const InternalErr = -32603
// 'actual' type of it so when we send it back over the
// wire, we don't confuse the other side.
type Id struct {
intVal int64
intVal uint32
strVal string
}

Expand All @@ -52,11 +52,11 @@ func (id *Id) UnmarshalJSON(data []byte) error {
id.strVal = string(data[1 : len(data)-1])
return nil
case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
val, err := strconv.ParseInt(string(data), 10, 64)
val, err := strconv.ParseUint(string(data), 10, 32)
if err != nil {
return NewError(nil, InvalidRequest, fmt.Sprintf("Invalid Id value: %s", string(data)))
}
id.intVal = val
id.intVal = uint32(val)
return nil
case '{': // objects not allowed!
fallthrough
Expand All @@ -75,7 +75,7 @@ func (id Id) String() string {
if id.strVal != "" {
return id.strVal
}
return strconv.FormatInt(id.intVal, 10)
return strconv.FormatInt(int64(id.intVal), 10)
}

func NewId(val string) *Id {
Expand All @@ -84,7 +84,7 @@ func NewId(val string) *Id {
}
}

func NewIdAsInt(val int64) *Id {
func NewIdAsInt(val uint32) *Id {
return &Id{
intVal: val,
}
Expand Down