Skip to content

Commit a06bade

Browse files
authored
Merge pull request #954 from ellemouton/sql7Accounts7
[sql-7] accounts: add SQL implementation of the accounts store
2 parents 400a129 + 0ec5d94 commit a06bade

File tree

8 files changed

+845
-3
lines changed

8 files changed

+845
-3
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ jobs:
253253
unit_type:
254254
- unit-race
255255
- unit
256+
- unit dbbackend=postgres
257+
- unit dbbackend=sqlite
256258
steps:
257259
- name: git checkout
258260
uses: actions/checkout@v4

accounts/interface.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package accounts
22

33
import (
4+
"bytes"
45
"context"
6+
"encoding/binary"
57
"encoding/hex"
68
"errors"
79
"fmt"
@@ -55,6 +57,31 @@ func ParseAccountID(idStr string) (*AccountID, error) {
5557
return &id, nil
5658
}
5759

60+
// ToInt64 converts an AccountID to its int64 representation.
61+
func (a AccountID) ToInt64() (int64, error) {
62+
var value int64
63+
buf := bytes.NewReader(a[:])
64+
if err := binary.Read(buf, byteOrder, &value); err != nil {
65+
return 0, err
66+
}
67+
68+
return value, nil
69+
}
70+
71+
// AccountIDFromInt64 converts an int64 to an AccountID.
72+
func AccountIDFromInt64(value int64) (AccountID, error) {
73+
var (
74+
a = AccountID{}
75+
buf = new(bytes.Buffer)
76+
)
77+
if err := binary.Write(buf, byteOrder, value); err != nil {
78+
return a, err
79+
}
80+
copy(a[:], buf.Bytes())
81+
82+
return a, nil
83+
}
84+
5885
// String returns the string representation of the AccountID.
5986
func (a AccountID) String() string {
6087
return hex.EncodeToString(a[:])

0 commit comments

Comments
 (0)