Skip to content

Commit

Permalink
Merge pull request #94 from renproject/release/0.1.14
Browse files Browse the repository at this point in the history
Release v0.1.14
  • Loading branch information
jazg committed Oct 28, 2020
2 parents 8740014 + cc5577c commit 916ee4d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.14
- Fix an issue when trying to insert a nil address list to storage.
- Update mint fees in JSON-RPC response

## 0.1.13
- Update to Darknode v0.2.24 (add recover mechanism in the rpc server)
- Use persistent storage (database) for MultiAddress store.
Expand Down
25 changes: 24 additions & 1 deletion resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package resolver
import (
"context"
"crypto/ecdsa"
"encoding/json"
"fmt"
"math/big"
"net/http"
"net/url"

Expand Down Expand Up @@ -78,7 +80,28 @@ func (resolver *Resolver) QueryStat(ctx context.Context, id interface{}, params
}

func (resolver *Resolver) QueryFees(ctx context.Context, id interface{}, params *jsonrpc.ParamsQueryFees, req *http.Request) jsonrpc.Response {
return resolver.handleMessage(ctx, id, jsonrpc.MethodQueryFees, *params, req, false)
response := resolver.handleMessage(ctx, id, jsonrpc.MethodQueryFees, *params, req, false)
if response.Error != nil{
return response
}
// Manually override the mint fee in the result, as it has changed in the
// contracts.
resBytes, err := json.Marshal(response.Result)
if err != nil {
jsonErr := jsonrpc.NewError(jsonrpc.ErrorCodeInternal, fmt.Sprintf("marshaling result: %v", err), nil)
return jsonrpc.NewResponse(id, nil, &jsonErr)
}
var res jsonrpc.ResponseQueryFees
if err := json.Unmarshal(resBytes, &res); err != nil {
jsonErr := jsonrpc.NewError(jsonrpc.ErrorCodeInternal, fmt.Sprintf("unmarshaling result: %v", err), nil)
return jsonrpc.NewResponse(id, nil, &jsonErr)
}
res.BCH.Ethereum.Mint = abi.U64{Int: big.NewInt(20)}
res.BTC.Ethereum.Mint = abi.U64{Int: big.NewInt(20)}
res.ZEC.Ethereum.Mint = abi.U64{Int: big.NewInt(20)}
response.Result = res

return response
}

func (resolver *Resolver) QueryTxs(ctx context.Context, id interface{}, params *jsonrpc.ParamsQueryTxs, req *http.Request) jsonrpc.Response {
Expand Down
4 changes: 4 additions & 0 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func (s *store) Insert(addr addr.MultiAddress) error {
}

func (s *store) InsertAddresses(addrs addr.MultiAddresses) error {
if len(addrs) == 0 {
return nil
}

// According to https://stackoverflow.com/questions/12486436/how-do-i-batch-sql-statements-with-package-database-sql/25192138#25192138
values := make([]string, len(addrs))
for i, addr := range addrs {
Expand Down
9 changes: 9 additions & 0 deletions store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ var _ = Describe("MultiAddrStore", func() {
Expect(size).Should(Equal(50))
})

It("should be able to batch insert when giving a nil address list", func() {
db := init(dbname)
defer cleanup(db)

store, err := New(db, nil)
Expect(err).ShouldNot(HaveOccurred())
Expect(store.InsertAddresses(nil)).Should(Succeed())
})

It("should return the size of the db", func() {
db := init(dbname)
defer cleanup(db)
Expand Down
5 changes: 0 additions & 5 deletions updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ func (updater *Updater) updateMultiAddress(ctx context.Context) {
response, err := updater.client.SendRequest(queryCtx, address, request, nil)
if err != nil {
updater.logger.Warnf("[updater] cannot connect to node %v: %v", multi.String(), err)
if !updater.isBootstrap(multi) {
if err := updater.multiStore.Delete(multi.ID().String()); err != nil {
updater.logger.Warnf("[updater] cannot delete multi address from db : %v", err)
}
}
return
}

Expand Down

0 comments on commit 916ee4d

Please sign in to comment.