diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..32068a2 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +# For now, tag everyone who wants to participate +* @deso-protocol/reviewers diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0187725 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,60 @@ +name: ci + +on: + pull_request: {} + push: + branches: + - main + +jobs: +# go-fmt: +# name: go-fmt +# runs-on: ubuntu-20.04 +# +# steps: +# - name: Install Go +# uses: actions/setup-go@v2 +# with: +# go-version: "1.20" +# +# - name: Checkout branch +# uses: actions/checkout@v3 +# +# # Fail if go-fmt recommends any changes. +# - name: Run go fmt +# run: if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi + + go-test: + name: go-test + runs-on: ubuntu-20.04 + + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: "1.20" + + - name: Checkout branch + uses: actions/checkout@v3 + + - name: Cache dependencies + id: cache-dependencies + uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + # Install dependencies if not found in cache. + - name: Install dependencies + if: steps.cache-dependencies.outputs.cache-hit != 'true' + run: go mod download && go install + + - name: Build package + run: go build + + - name: Run go test + run: go test -v ./ diff --git a/README.md b/README.md index 43dd259..ad96611 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ +# deso-protocol/Uint256 +This is a forked version of (https://github.com/holiman/uint256)[https://github.com/holiman/uint256]. +When deso-protocol go repositories began using this dependency, uint256 would marshal as a hex string. +The source updated its code to better mirror the BigInt library to marshal as a decimal string. +In order to maintain our APIs as they were but still take advantage of the latest updates, we have fork +the repository and only made changes to revert to using a hex string for marshaling. + # Fixed size 256-bit math library This is a library specialized at replacing the big.Int library for math based on 256-bit types, used by both diff --git a/conversion.go b/conversion.go index 640197c..fecc320 100644 --- a/conversion.go +++ b/conversion.go @@ -692,7 +692,7 @@ func (z *Int) EncodeRLP(w io.Writer) error { // MarshalText implements encoding.TextMarshaler // MarshalText marshals using the decimal representation (compatible with big.Int) func (z *Int) MarshalText() ([]byte, error) { - return []byte(z.Dec()), nil + return []byte(z.Hex()), nil } // MarshalJSON implements json.Marshaler. @@ -703,7 +703,7 @@ func (z *Int) MarshalText() ([]byte, error) { // integer space. Thus, U256 uses string-format, which is not compatible with // big.int (big.Int refuses to unmarshal a string representation). func (z *Int) MarshalJSON() ([]byte, error) { - return []byte(`"` + z.Dec() + `"`), nil + return []byte(`"` + z.Hex() + `"`), nil } // UnmarshalJSON implements json.Unmarshaler. UnmarshalJSON accepts either @@ -719,7 +719,7 @@ func (z *Int) UnmarshalJSON(input []byte) error { // String returns the decimal encoding of b. func (z *Int) String() string { - return z.Dec() + return z.Hex() } const ( diff --git a/conversion_test.go b/conversion_test.go index 81f2f58..c5dd639 100644 --- a/conversion_test.go +++ b/conversion_test.go @@ -1278,19 +1278,19 @@ func TestEnDecode(t *testing.T) { if have, want := intSample.Hex(), fmt.Sprintf("0x%s", bigSample.Text(16)); have != want { t.Fatalf("test %d #1, have %v, want %v", i, have, want) } - if have, want := intSample.String(), bigSample.String(); have != want { + if have, want := intSample.String(), wantHex; have != want { t.Fatalf("test %d String(), have %v, want %v", i, have, want) } { have, _ := intSample.MarshalText() - want, _ := bigSample.MarshalText() + want := []byte(wantHex) if !bytes.Equal(have, want) { t.Fatalf("test %d MarshalText, have %q, want %q", i, have, want) } } { have, _ := intSample.MarshalJSON() - want := []byte(fmt.Sprintf(`"%s"`, bigSample.Text(10))) + want := []byte(fmt.Sprintf(`"0x%s"`, bigSample.Text(16))) if !bytes.Equal(have, want) { t.Fatalf("test %d MarshalJSON, have %q, want %q", i, have, want) }