nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: trustwallet/blockatlas
Pull request #952 (2020-03-03 06:45:52)

[Observer] Delete pointers in getDirection


Patch:
diff --git a/observer/observer.go b/observer/observer.go
index 658ec8f..aaf8470 100644
--- a/observer/observer.go
+++ b/observer/observer.go
@@ -89,9 +89,9 @@ func getDirection(tx blockatlas.Tx, address string) blockatlas.Direction {
 		return bitcoin.InferDirection(&tx, addressSet)
 	}
 	switch meta := tx.Meta.(type) {
-	case *blockatlas.TokenTransfer:
+	case blockatlas.TokenTransfer:
 		return determineDirection(address, meta.From, meta.To)
-	case *blockatlas.NativeTokenTransfer:
+	case blockatlas.NativeTokenTransfer:
 		return determineDirection(address, meta.From, meta.To)
 	default:
 		return determineDirection(address, tx.From, tx.To)


Test patch:
diff --git a/observer/observer_test.go b/observer/observer_test.go
index 91c4c32..9c6fa44 100644
--- a/observer/observer_test.go
+++ b/observer/observer_test.go
@@ -174,7 +174,7 @@ func Test_getDirection(t *testing.T) {
 		{"Test NativeTokenTransfer Direction Self",
 			args{
 				blockatlas.Tx{
-					Meta: &blockatlas.NativeTokenTransfer{
+					Meta: blockatlas.NativeTokenTransfer{
 						From:     "0x5574Cd97432cEd0D7Caf58ac3c4fEDB2061C98fB",
 						To:       "0x5574Cd97432cEd0D7Caf58ac3c4fEDB2061C98fB",
 					},
@@ -184,7 +184,7 @@ func Test_getDirection(t *testing.T) {
 		{"Test NativeTokenTransfer Direction Outgoing",
 			args{
 				blockatlas.Tx{
-					Meta: &blockatlas.NativeTokenTransfer{
+					Meta: blockatlas.NativeTokenTransfer{
 						From:     "0x5574Cd97432cEd0D7Caf58ac3c4fEDB2061C98fB",
 						To:       "0x74c8199372c584DAB8b14c519bc8BC8C622F37b7",
 					},
@@ -194,7 +194,7 @@ func Test_getDirection(t *testing.T) {
 		{"Test NativeTokenTransfer Direction Incoming",
 			args{
 				blockatlas.Tx{
-					Meta: &blockatlas.NativeTokenTransfer{
+					Meta: blockatlas.NativeTokenTransfer{
 						From:     "0x74c8199372c584DAB8b14c519bc8BC8C622F37b7",
 						To:       "0x5574Cd97432cEd0D7Caf58ac3c4fEDB2061C98fB",
 					},
@@ -204,7 +204,7 @@ func Test_getDirection(t *testing.T) {
 		{"Test TokenTransfer Direction Self",
 			args{
 				blockatlas.Tx{
-					Meta: &blockatlas.TokenTransfer{
+					Meta: blockatlas.TokenTransfer{
 						From:     "0x5574Cd97432cEd0D7Caf58ac3c4fEDB2061C98fB",
 						To:       "0x5574Cd97432cEd0D7Caf58ac3c4fEDB2061C98fB",
 					},
@@ -214,7 +214,7 @@ func Test_getDirection(t *testing.T) {
 		{"Test TokenTransfer Direction Outgoing",
 			args{
 				blockatlas.Tx{
-					Meta: &blockatlas.TokenTransfer{
+					Meta: blockatlas.TokenTransfer{
 						From:     "0x5574Cd97432cEd0D7Caf58ac3c4fEDB2061C98fB",
 						To:       "0x74c8199372c584DAB8b14c519bc8BC8C622F37b7",
 					},
@@ -224,7 +224,7 @@ func Test_getDirection(t *testing.T) {
 		{"Test TokenTransfer Direction Incoming",
 			args{
 				blockatlas.Tx{
-					Meta: &blockatlas.TokenTransfer{
+					Meta: blockatlas.TokenTransfer{
 						From:     "0x74c8199372c584DAB8b14c519bc8BC8C622F37b7",
 						To:       "0x5574Cd97432cEd0D7Caf58ac3c4fEDB2061C98fB",
 					},
Repository: trustwallet/blockatlas
Pull request #985 (2020-03-31 02:27:16)

fix: Get receiver for delegate transfer


Patch:
diff --git a/platform/tezos/model.go b/platform/tezos/model.go
index 970c08c..451b39c 100644
--- a/platform/tezos/model.go
+++ b/platform/tezos/model.go
@@ -109,3 +109,11 @@ func (t *Transaction) Direction(address string) blockatlas.Direction {
 
 	return blockatlas.DirectionIncoming
 }
+
+func (t *Transaction) GetReceiver() string {
+	if t.Receiver != "" {
+		return t.Receiver
+	} else {
+		return t.Delegate
+	}
+}
diff --git a/platform/tezos/transaction.go b/platform/tezos/transaction.go
index 415b771..5e1d76c 100644
--- a/platform/tezos/transaction.go
+++ b/platform/tezos/transaction.go
@@ -40,7 +40,7 @@ func NormalizeTx(srcTx Transaction, address string) (blockatlas.Tx, bool) {
 		From:   srcTx.Sender,
 		ID:     srcTx.Hash,
 		Status: srcTx.Status(),
-		To:     srcTx.Receiver,
+		To:     srcTx.GetReceiver(),
 		Type:   srcTx.TransferType(),
 	}
 	if address != "" {


Test patch:
diff --git a/platform/tezos/model_test.go b/platform/tezos/model_test.go
index 773b11d..9d81516 100644
--- a/platform/tezos/model_test.go
+++ b/platform/tezos/model_test.go
@@ -128,4 +128,19 @@ func TestTransaction_Status(t *testing.T) {
 		})
 	}
 
+	testsGetReceiver := []struct {
+		name string
+		in   Transaction
+		out  string
+	}{
+		{"Should get receiver when no delegate", Transaction{Receiver: addr1, Delegate: ""}, addr1},
+		{"Should get receiver when delegate", Transaction{Receiver: "", Delegate: addr1}, addr1},
+	}
+
+	for _, tt := range testsGetReceiver {
+		t.Run(tt.name, func(t *testing.T) {
+			assert.Equal(t, tt.out, tt.in.GetReceiver())
+		})
+	}
+
 }
Repository: trustwallet/blockatlas
Pull request #987 (2020-03-31 03:41:03)

Fix decimal value


Patch:
diff --git a/platform/tezos/transaction.go b/platform/tezos/transaction.go
index 930fab6..87f27ac 100644
--- a/platform/tezos/transaction.go
+++ b/platform/tezos/transaction.go
@@ -46,7 +46,8 @@ func NormalizeTx(srcTx Transaction, address string) (blockatlas.Tx, bool) {
 	if address != "" {
 		tx.Direction = srcTx.Direction(address)
 	}
-	value := blockatlas.Amount(numbers.Float64toString(srcTx.Volume))
+
+	value := blockatlas.Amount(numbers.DecimalExp(numbers.Float64toString(srcTx.Volume), 6))
 	switch srcTx.TransferType() {
 	case blockatlas.TxAnyAction:
 		tx.Meta = blockatlas.AnyAction{


Test patch:
diff --git a/platform/tezos/transaction_test.go b/platform/tezos/transaction_test.go
index cc8febf..5bf0a9d 100644
--- a/platform/tezos/transaction_test.go
+++ b/platform/tezos/transaction_test.go
@@ -34,7 +34,7 @@ var (
 		Direction: "yourself",
 		Memo:      "",
 		Meta: blockatlas.Transfer{
-			Value:    "0.000001",
+			Value:    "1",
 			Symbol:   "XTZ",
 			Decimals: 6,
 		},
Repository: trustwallet/blockatlas
Pull request #988 (2020-03-31 03:54:08)

Create Maintance template
skip ci


Patch:
diff --git a/.github/ISSUE_TEMPLATE/MAINTANCE_TEMPLATE b/.github/ISSUE_TEMPLATE/MAINTANCE_TEMPLATE
new file mode 100644
index 0000000..38e8634
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/MAINTANCE_TEMPLATE
@@ -0,0 +1,16 @@
+---
+name: Maintance
+about: Deprecate old functionality or routes
+title: ''
+labels: 'Type: Maintance'
+assignees: ''
+
+---
+
+<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺ 
+v                 ✰  Thanks for opening an issue! ✰                    v
+v    Before smashing the submit button please review the template.     v
+v               Don't forget to set the priority label.                v
+v       Please also ensure that this is not a duplicate issue :)       v  
+☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >  -->
+
diff --git a/platform/tezos/transaction.go b/platform/tezos/transaction.go
index 930fab6..73347a0 100644
--- a/platform/tezos/transaction.go
+++ b/platform/tezos/transaction.go
@@ -36,7 +36,7 @@ func NormalizeTx(srcTx Transaction, address string) (blockatlas.Tx, bool) {
 		Coin:   coin.XTZ,
 		Date:   srcTx.BlockTimestamp(),
 		Error:  srcTx.ErrorMsg(),
-		Fee:    blockatlas.Amount(numbers.Float64toString(srcTx.Fee)),
+		Fee:    blockatlas.Amount(numbers.DecimalExp(numbers.Float64toString(srcTx.Fee), 6)),
 		From:   srcTx.Sender,
 		ID:     srcTx.Hash,
 		Status: srcTx.Status(),
@@ -46,7 +46,8 @@ func NormalizeTx(srcTx Transaction, address string) (blockatlas.Tx, bool) {
 	if address != "" {
 		tx.Direction = srcTx.Direction(address)
 	}
-	value := blockatlas.Amount(numbers.Float64toString(srcTx.Volume))
+
+	value := blockatlas.Amount(numbers.DecimalExp(numbers.Float64toString(srcTx.Volume), 6))
 	switch srcTx.TransferType() {
 	case blockatlas.TxAnyAction:
 		tx.Meta = blockatlas.AnyAction{


Test patch:
diff --git a/platform/tezos/transaction_test.go b/platform/tezos/transaction_test.go
index cc8febf..aa98ce7 100644
--- a/platform/tezos/transaction_test.go
+++ b/platform/tezos/transaction_test.go
@@ -26,7 +26,7 @@ var (
 		Coin:      1729,
 		From:      addr1,
 		To:        addr1,
-		Fee:       "0.0015",
+		Fee:       "1500",
 		Date:      1582894746,
 		Block:     843988,
 		Status:    "completed",
@@ -34,7 +34,7 @@ var (
 		Direction: "yourself",
 		Memo:      "",
 		Meta: blockatlas.Transfer{
-			Value:    "0.000001",
+			Value:    "1",
 			Symbol:   "XTZ",
 			Decimals: 6,
 		},
Repository: trustwallet/blockatlas
Pull request #990 (2020-03-31 04:07:09)

Fix fee decimal


Patch:
diff --git a/platform/tezos/transaction.go b/platform/tezos/transaction.go
index 87f27ac..73347a0 100644
--- a/platform/tezos/transaction.go
+++ b/platform/tezos/transaction.go
@@ -36,7 +36,7 @@ func NormalizeTx(srcTx Transaction, address string) (blockatlas.Tx, bool) {
 		Coin:   coin.XTZ,
 		Date:   srcTx.BlockTimestamp(),
 		Error:  srcTx.ErrorMsg(),
-		Fee:    blockatlas.Amount(numbers.Float64toString(srcTx.Fee)),
+		Fee:    blockatlas.Amount(numbers.DecimalExp(numbers.Float64toString(srcTx.Fee), 6)),
 		From:   srcTx.Sender,
 		ID:     srcTx.Hash,
 		Status: srcTx.Status(),


Test patch:
diff --git a/platform/tezos/transaction_test.go b/platform/tezos/transaction_test.go
index 5bf0a9d..aa98ce7 100644
--- a/platform/tezos/transaction_test.go
+++ b/platform/tezos/transaction_test.go
@@ -26,7 +26,7 @@ var (
 		Coin:      1729,
 		From:      addr1,
 		To:        addr1,
-		Fee:       "0.0015",
+		Fee:       "1500",
 		Date:      1582894746,
 		Block:     843988,
 		Status:    "completed",
Repository: trustwallet/blockatlas
Pull request #1022 (2020-04-08 20:55:40)

[Gincache] Update  Cache-Control logic in CacheMiddleware


Patch:
diff --git a/api/middleware/cache.go b/api/middleware/cache.go
index 8d87aa0..916483a 100644
--- a/api/middleware/cache.go
+++ b/api/middleware/cache.go
@@ -120,21 +120,21 @@ func (mc *memCache) setCache(k string, x interface{}, d time.Duration) {
 	memoryCache.cache.Set(k, b, d)
 }
 
-func (mc *memCache) getCache(key string) (cacheResponse, time.Time, error) {
+func (mc *memCache) getCache(key string) (cacheResponse, error) {
 	var result cacheResponse
-	c, exp, ok := mc.cache.GetWithExpiration(key)
+	c, ok := mc.cache.Get(key)
 	if !ok {
-		return result, time.Time{}, fmt.Errorf("gin-cache: invalid cache key %s", key)
+		return result, fmt.Errorf("gin-cache: invalid cache key %s", key)
 	}
 	r, ok := c.([]byte)
 	if !ok {
-		return result, time.Time{}, errors.E("validator cache: failed to cast cache to bytes")
+		return result, errors.E("validator cache: failed to cast cache to bytes")
 	}
 	err := json.Unmarshal(r, &result)
 	if err != nil {
-		return result, time.Time{}, errors.E(err, "not found")
+		return result, errors.E(err, "not found")
 	}
-	return result, exp, nil
+	return result, nil
 }
 
 func generateKey(c *gin.Context) string {
@@ -154,12 +154,12 @@ func CacheMiddleware(expiration time.Duration, handle gin.HandlerFunc) gin.Handl
 	return func(c *gin.Context) {
 		defer c.Next()
 		key := generateKey(c)
-		mc, exp, err := memoryCache.getCache(key)
+		cacheControlValue := uint(expiration.Seconds())
+		mc, err := memoryCache.getCache(key)
 		if err != nil || mc.Data == nil {
 			writer := newCachedWriter(expiration, c.Writer, key)
 
-			expForSet := uint(expiration.Seconds())
-			writer.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d", expForSet))
+			writer.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d", cacheControlValue))
 
 			c.Writer = writer
 			handle(c)
@@ -176,13 +176,7 @@ func CacheMiddleware(expiration time.Duration, handle gin.HandlerFunc) gin.Handl
 			}
 		}
 
-		expCacheTime := (exp.UnixNano() - time.Now().UnixNano()) / int64(time.Second)
-
-		if expCacheTime < 0 {
-			logger.Error("Invalid expiration time")
-		} else {
-			c.Writer.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d", expCacheTime))
-		}
+		c.Writer.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d", cacheControlValue))
 
 		_, err = c.Writer.Write(mc.Data)
 		if err != nil {


Test patch:
diff --git a/api/middleware/cache_test.go b/api/middleware/cache_test.go
index 72d0aaf..70b680b 100644
--- a/api/middleware/cache_test.go
+++ b/api/middleware/cache_test.go
@@ -78,7 +78,7 @@ func TestCacheControl(t *testing.T) {
 	w2 := performRequest("GET", "/cache_ping_control", router)
 	w2CacheControl := w2.Header().Get("Cache-Control")
 
-	assert.NotEqual(t, w1CacheControl, w2CacheControl)
+	assert.Equal(t, w1CacheControl, w2CacheControl)
 	assert.Equal(t, w1.Body.String(), w2.Body.String())
 
 	assert.Equal(t, http.StatusOK, w1.Code)
Repository: segmentio/encoding
Pull request #59 (2021-01-13 19:07:06)

json: add AppendEscaped function for directly encoding strings
This change exposes an `AppendEscaped` function that directly encodes a string into it's JSON-encoded counterpart by appending it to a `[]byte` buffer. This works similarly to the `Append` function, but it bypasses the type matching and it is does not produce an `error`. For example:

```go
b := json.AppendEscaped([]byte{}, `"escaped"	<value>`, json.EscapeHTML)
println(string(b)) // "\"escaped\"\t\u003cvalue\u003e"
```


Patch:
diff --git a/json/json.go b/json/json.go
index 60e3366..294b724 100644
--- a/json/json.go
+++ b/json/json.go
@@ -142,6 +142,15 @@ func Append(b []byte, x interface{}, flags AppendFlags) ([]byte, error) {
 	return b, err
 }
 
+// AppendEscaped appends s to b with the string escaped as a JSON value.
+// This will include the starting and ending quote characters, and the
+// appropriate characters will be escaped correctly for JSON encoding.
+func AppendEscaped(b []byte, s string, flags AppendFlags) []byte {
+	e := encoder{flags: flags}
+	b, _ = e.encodeString(b, unsafe.Pointer(&s))
+	return b
+}
+
 // Compact is documented at https://golang.org/pkg/encoding/json/#Compact
 func Compact(dst *bytes.Buffer, src []byte) error {
 	return json.Compact(dst, src)


Test patch:
diff --git a/json/json_test.go b/json/json_test.go
index 9ae8cbe..9b06337 100644
--- a/json/json_test.go
+++ b/json/json_test.go
@@ -1646,3 +1646,46 @@ func TestSetTrustRawMessage(t *testing.T) {
 		)
 	}
 }
+
+func TestAppendEscaped(t *testing.T) {
+	t.Run("basic", func(t *testing.T) {
+		b := AppendEscaped([]byte{}, `value`, AppendFlags(0))
+		exp := []byte(`"value"`)
+		if bytes.Compare(exp, b) != 0 {
+			t.Error(
+				"unexpected encoding:",
+				"expected", exp,
+				"got", b,
+			)
+		}
+	})
+
+	t.Run("escaped", func(t *testing.T) {
+		b := AppendEscaped([]byte{}, `"escaped"	<value>`, EscapeHTML)
+		exp := []byte(`"\"escaped\"\t\u003cvalue\u003e"`)
+		if bytes.Compare(exp, b) != 0 {
+			t.Error(
+				"unexpected encoding:",
+				"expected", exp,
+				"got", b,
+			)
+		}
+	})
+
+	t.Run("build", func(t *testing.T) {
+		b := []byte{}
+		b = append(b, '{')
+		b = AppendEscaped(b, `key`, EscapeHTML)
+		b = append(b, ':')
+		b = AppendEscaped(b, `"escaped"	<value>`, EscapeHTML)
+		b = append(b, '}')
+		exp := []byte(`{"key":"\"escaped\"\t\u003cvalue\u003e"}`)
+		if bytes.Compare(exp, b) != 0 {
+			t.Error(
+				"unexpected encoding:",
+				"expected", exp,
+				"got", b,
+			)
+		}
+	})
+}
Repository: segmentio/encoding
Pull request #83 (2021-03-26 03:45:34)

iso8601.Parse() timezone fix
This fixes a bug introduced by https://github.com/segmentio/encoding/pull/82. `time.Unix()` attaches the local timezone. This wasn't caught by the unit tests as `time.Equal()` ignores the timezone.


Patch:
diff --git a/iso8601/parse.go b/iso8601/parse.go
index abfeff1..f6b6c55 100644
--- a/iso8601/parse.go
+++ b/iso8601/parse.go
@@ -52,7 +52,7 @@ func Parse(input string) (time.Time, error) {
 		}
 
 		unixSeconds := int64(daysSinceEpoch(year, month, day))*86400 + int64(hour*3600+minute*60+second)
-		return time.Unix(unixSeconds, 0), nil
+		return time.Unix(unixSeconds, 0).UTC(), nil
 
 	case 24: // YYYY-MM-DDTHH:MM:SS.MMMZ
 		t1 := binary.LittleEndian.Uint64(b)
@@ -89,7 +89,7 @@ func Parse(input string) (time.Time, error) {
 		}
 
 		unixSeconds := int64(daysSinceEpoch(year, month, day))*86400 + int64(hour*3600+minute*60+second)
-		return time.Unix(unixSeconds, int64(millis*1e6)), nil
+		return time.Unix(unixSeconds, int64(millis*1e6)).UTC(), nil
 
 	default:
 		return time.Parse(time.RFC3339Nano, input)


Test patch:
diff --git a/iso8601/parse_test.go b/iso8601/parse_test.go
index 4045392..c2f2341 100644
--- a/iso8601/parse_test.go
+++ b/iso8601/parse_test.go
@@ -42,6 +42,8 @@ func TestParse(t *testing.T) {
 				t.Error(err)
 			} else if !actual.Equal(expect) {
 				t.Errorf("unexpected time: %v vs expected %v", actual, expect)
+			} else if actual.Location().String() != expect.Location().String() {
+				t.Errorf("unexpected timezone: %v vs expected %v", actual.Location().String(), expect.Location().String())
 			}
 		})
 	}
Repository: trustwallet/blockatlas
Pull request #1187 (2020-08-13 10:30:07)

[Platform] Fix aeternity amount issue
Closes https://github.com/trustwallet/blockatlas/issues/1183


Patch:
diff --git a/platform/aeternity/transaction.go b/platform/aeternity/transaction.go
index 48adf1f..2d904c9 100644
--- a/platform/aeternity/transaction.go
+++ b/platform/aeternity/transaction.go
@@ -4,6 +4,7 @@ import (
 	"encoding/base64"
 	"github.com/trustwallet/blockatlas/coin"
 	"github.com/trustwallet/blockatlas/pkg/blockatlas"
+	"github.com/trustwallet/blockatlas/pkg/numbers"
 	"strings"
 )
 
@@ -15,30 +16,40 @@ func (p *Platform) GetTxsByAddress(address string) (blockatlas.TxPage, error) {
 
 	var txs []blockatlas.Tx
 	for _, srcTx := range addressTxs {
-		txs = append(txs, NormalizeTx(&srcTx))
+		tx, err := NormalizeTx(&srcTx)
+		if err != nil {
+			continue
+		}
+		txs = append(txs, tx)
 	}
 	return txs, nil
 }
 
-func NormalizeTx(srcTx *Transaction) blockatlas.Tx {
+func NormalizeTx(srcTx *Transaction) (blockatlas.Tx, error) {
 	txValue := srcTx.TxValue
+	decimals := coin.Coins[coin.AE].Decimals
+	amountFloat, err := txValue.Amount.Float64()
+	if err != nil {
+		return blockatlas.Tx{}, err
+	}
+	amount := numbers.Float64toString(amountFloat)
 	return blockatlas.Tx{
 		ID:       srcTx.Hash,
 		Coin:     coin.AE,
 		From:     txValue.Sender,
 		To:       txValue.Recipient,
 		Fee:      blockatlas.Amount(txValue.Fee),
-		Date:     int64(srcTx.Timestamp) / 1000,
+		Date:     srcTx.Timestamp / 1000,
 		Block:    srcTx.BlockHeight,
 		Memo:     getPayload(txValue.Payload),
 		Status:   blockatlas.StatusCompleted,
 		Sequence: txValue.Nonce,
 		Meta: blockatlas.Transfer{
-			Value:    blockatlas.Amount(txValue.Amount),
+			Value:    blockatlas.Amount(amount),
 			Symbol:   coin.Coins[coin.AE].Symbol,
-			Decimals: coin.Coins[coin.AE].Decimals,
+			Decimals: decimals,
 		},
-	}
+	}, nil
 }
 
 func getPayload(encodedPayload string) string {


Test patch:
diff --git a/platform/aeternity/transaction_test.go b/platform/aeternity/transaction_test.go
index fec5dbb..8392602 100644
--- a/platform/aeternity/transaction_test.go
+++ b/platform/aeternity/transaction_test.go
@@ -63,7 +63,8 @@ func testNormalize(t *testing.T, _test *test) {
 		return
 	}
 
-	tx := NormalizeTx(&srcTx)
+	tx, err := NormalizeTx(&srcTx)
+	assert.Nil(t, err)
 
 	resJSON, err := json.Marshal(&tx)
 	if err != nil {