Skip to content

Commit e88802c

Browse files
authored
Merge pull request #5689 from tamirms/protocol-23
Merge master into protocol-23 branch
2 parents b5c1291 + 2ffb516 commit e88802c

File tree

112 files changed

+10348
-854
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+10348
-854
lines changed

.github/workflows/horizon.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
name: Integration tests
1111
strategy:
1212
matrix:
13-
os: [ubuntu-20.04, ubuntu-22.04]
13+
os: [ubuntu-22.04]
1414
go: ["1.22", "1.23"]
1515
pg: [12, 16]
1616
protocol-version: [22]

amount/main.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ func ParseInt64(v string) (int64, error) {
8282
return i, nil
8383
}
8484

85+
// MustParseInt64Raw simply converts an string into a 64-bit signed integer
86+
func MustParseInt64Raw(v string) int64 {
87+
i, err := strconv.ParseInt(v, 10, 64)
88+
if err != nil {
89+
panic(err)
90+
}
91+
return i
92+
}
93+
8594
// IntStringToAmount converts string integer value and converts it to stellar
8695
// "amount". In other words, it divides the given string integer value by 10^7
8796
// and returns the string representation of that number.
@@ -139,3 +148,17 @@ func StringFromInt64(v int64) string {
139148
r.Quo(r, bigOne)
140149
return r.FloatString(7)
141150
}
151+
152+
// No conversion. Simply convert int64 to string. Useful to have this in one place, should the underlying implementation change
153+
func String64Raw(v xdr.Int64) string {
154+
return strconv.FormatInt(int64(v), 10)
155+
}
156+
157+
func String128Raw(v xdr.Int128Parts) string {
158+
// the upper half of the i128 always indicates its sign regardless of its
159+
// value, just like a native signed type
160+
val := big.NewInt(int64(v.Hi))
161+
val.Lsh(val, 64).Add(val, new(big.Int).SetUint64(uint64(v.Lo)))
162+
163+
return val.String()
164+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ require (
135135
github.com/gavv/monotime v0.0.0-20161010190848-47d58efa6955 // indirect
136136
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
137137
github.com/golang/protobuf v1.5.4 // indirect
138-
github.com/google/go-cmp v0.6.0 // indirect
138+
github.com/google/go-cmp v0.7.0
139139
github.com/google/go-querystring v0.0.0-20160401233042-9235644dd9e5 // indirect
140140
github.com/googleapis/gax-go/v2 v2.12.4 // indirect
141141
github.com/hashicorp/golang-lru v1.0.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
237237
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
238238
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
239239
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
240-
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
241-
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
240+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
241+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
242242
github.com/google/go-querystring v0.0.0-20160401233042-9235644dd9e5 h1:oERTZ1buOUYlpmKaqlO5fYmz8cZ1rYu5DieJzF4ZVmU=
243243
github.com/google/go-querystring v0.0.0-20160401233042-9235644dd9e5/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
244244
github.com/google/gopacket v1.1.20-0.20210429153827-3eaba0894325/go.mod h1:riddUzxTSBpJXk3qBHtYr4qOhFhT6k/1c0E3qkQjQpA=

ingest/address/address.pb.go

Lines changed: 0 additions & 206 deletions
This file was deleted.

ingest/asset/asset.go

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,63 @@
11
package asset
22

3+
import (
4+
"github.com/stellar/go/xdr"
5+
"strings"
6+
)
7+
38
// NewNativeAsset creates an Asset representing the native token (XLM).
49
func NewNativeAsset() *Asset {
510
return &Asset{AssetType: &Asset_Native{Native: true}}
611
}
712

8-
// NewIssuedAsset creates an Asset with an asset code and issuer.
9-
func NewIssuedAsset(assetCode, issuer string) *Asset {
13+
func NewProtoAsset(asset xdr.Asset) *Asset {
14+
if asset.IsNative() {
15+
return NewNativeAsset()
16+
}
1017
return &Asset{
1118
AssetType: &Asset_IssuedAsset{
1219
IssuedAsset: &IssuedAsset{
13-
AssetCode: assetCode,
14-
Issuer: issuer,
20+
// Need to trim the extra null characters from showing in the code when saving to assetCode
21+
AssetCode: strings.TrimRight(asset.GetCode(), "\x00"),
22+
Issuer: asset.GetIssuer(),
1523
},
1624
},
1725
}
1826
}
27+
28+
func (a *Asset) ToXdrAsset() xdr.Asset {
29+
if a == nil {
30+
panic("nil asset")
31+
}
32+
switch a := a.AssetType.(type) {
33+
case *Asset_Native:
34+
return xdr.MustNewNativeAsset()
35+
case *Asset_IssuedAsset:
36+
return xdr.MustNewCreditAsset(a.IssuedAsset.AssetCode, a.IssuedAsset.Issuer)
37+
}
38+
panic("unknown asset type")
39+
}
40+
41+
func (a *Asset) Equals(other *Asset) bool {
42+
// If both assets are the same type (native or issued asset)
43+
if a.AssetType == nil || other.AssetType == nil {
44+
return false
45+
}
46+
47+
switch a := a.AssetType.(type) {
48+
case *Asset_Native:
49+
if b, ok := other.AssetType.(*Asset_Native); ok {
50+
// Both assets are native; compare the native boolean value.
51+
// Ideally i could simply be returning true here, but it is more idiomatic to check for the flag equality
52+
return a.Native == b.Native
53+
}
54+
case *Asset_IssuedAsset:
55+
if b, ok := other.AssetType.(*Asset_IssuedAsset); ok {
56+
// Both assets are issued assets; compare their asset_code and issuer
57+
return a.IssuedAsset.AssetCode == b.IssuedAsset.AssetCode &&
58+
a.IssuedAsset.Issuer == b.IssuedAsset.Issuer
59+
}
60+
}
61+
62+
return false
63+
}

ingest/asset/asset_test.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
package asset
22

33
import (
4+
"github.com/stellar/go/xdr"
45
"github.com/stretchr/testify/assert"
56
"google.golang.org/protobuf/proto"
67
"testing"
78
)
89

10+
var (
11+
assetCode = "USDC"
12+
issuer = "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN"
13+
usdcAsset = xdr.MustNewCreditAsset(assetCode, issuer)
14+
)
15+
916
func TestNewNativeAsset(t *testing.T) {
1017
nativeAsset := NewNativeAsset()
1118

@@ -15,25 +22,26 @@ func TestNewNativeAsset(t *testing.T) {
1522
assert.True(t, nativeAsset.GetNative(), "Native asset should have Native set to true")
1623
}
1724

18-
func TestNewIssuedAsset(t *testing.T) {
19-
assetCode := "USDC"
20-
issuer := "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN"
21-
22-
issuedAsset := NewIssuedAsset(assetCode, issuer)
25+
func TestNewProtoAsset(t *testing.T) {
2326

24-
assert.NotNil(t, issuedAsset, "Issued asset should not be nil")
25-
assert.IsType(t, &Asset{}, issuedAsset, "Issued asset should be of type *Asset")
26-
assert.IsType(t, &Asset_IssuedAsset{}, issuedAsset.AssetType, "AssetType should be *Asset_IssuedAsset")
27+
usdcProtoAsset := NewProtoAsset(usdcAsset)
2728

29+
assert.NotNil(t, usdcProtoAsset, "asset should not be nil")
30+
assert.IsType(t, &Asset{}, usdcProtoAsset, "asset should be of type *Asset")
31+
assert.IsType(t, &Asset_IssuedAsset{}, usdcProtoAsset.AssetType, "AssetType should be *Asset_IssuedAsset")
2832
// Check issued asset fields
29-
assert.Equal(t, assetCode, issuedAsset.GetIssuedAsset().AssetCode, "Asset code should match")
30-
assert.Equal(t, issuer, issuedAsset.GetIssuedAsset().Issuer, "Issuer should match")
33+
assert.Equal(t, assetCode, usdcProtoAsset.GetIssuedAsset().AssetCode, "Asset code should match")
34+
assert.Equal(t, issuer, usdcProtoAsset.GetIssuedAsset().Issuer, "Issuer should match")
35+
36+
xlmProtoAsset := NewProtoAsset(xdr.MustNewNativeAsset())
37+
assert.NotNil(t, xlmProtoAsset, "asset should not be nil")
38+
assert.IsType(t, &Asset{}, xlmProtoAsset, "asset should be of type *Asset")
39+
assert.IsType(t, &Asset_Native{}, xlmProtoAsset.AssetType, "AssetType should be *Asset_Native")
40+
assert.True(t, xlmProtoAsset.GetNative(), "Native asset should have Native set to true")
3141
}
3242

3343
func TestAssetSerialization(t *testing.T) {
34-
assetCode := "USDC"
35-
issuer := "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN"
36-
original := NewIssuedAsset(assetCode, issuer)
44+
original := NewProtoAsset(usdcAsset)
3745

3846
serializedAsset, err := proto.Marshal(original)
3947
assert.NoError(t, err, "Failed to marshal asset")

0 commit comments

Comments
 (0)