-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
oracle, leveldb, cmd : move midpointPrice to the leveldb driver packa…
…ge and modify the way initializing bytes array
- Loading branch information
tok-kkk
committed
Aug 7, 2018
1 parent
ea20879
commit c72d0cc
Showing
9 changed files
with
94 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package leveldb | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/republicprotocol/republic-go/oracle" | ||
) | ||
|
||
// midpointPriceStorer implements MidpointPriceStorer interface with an | ||
// in-memory map implementation. Data will be lost every time it restarts. | ||
type midpointPriceStorer struct { | ||
mu *sync.Mutex | ||
prices oracle.MidpointPrice | ||
} | ||
|
||
// NewMidpointPriceStorer returns a new MidpointPriceStorer. | ||
func NewMidpointPriceStorer() oracle.MidpointPriceStorer { | ||
return &midpointPriceStorer{ | ||
mu: new(sync.Mutex), | ||
} | ||
} | ||
|
||
// PutMidpointPrice implements the MidpointPriceStorer interface. | ||
func (storer *midpointPriceStorer) PutMidpointPrice(midPointPrice oracle.MidpointPrice) error { | ||
storer.mu.Lock() | ||
defer storer.mu.Unlock() | ||
|
||
storer.prices = midPointPrice | ||
|
||
return nil | ||
} | ||
|
||
// MidpointPrice implements the MidpointPriceStorer interface. | ||
func (storer *midpointPriceStorer) MidpointPrice() (oracle.MidpointPrice, error) { | ||
storer.mu.Lock() | ||
defer storer.mu.Unlock() | ||
|
||
return storer.prices, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package leveldb_test | ||
|
||
import ( | ||
"math/rand" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
. "github.com/republicprotocol/republic-go/leveldb" | ||
|
||
"github.com/republicprotocol/republic-go/oracle" | ||
"github.com/republicprotocol/republic-go/testutils" | ||
) | ||
|
||
func init() { | ||
rand.Seed(time.Now().UnixNano()) | ||
} | ||
|
||
var _ = Describe("MidpointPrice storage", func() { | ||
|
||
Context("when storing and retrieving data", func() { | ||
|
||
It("should be able to get the right data we store", func() { | ||
storer := NewMidpointPriceStorer() | ||
emptyPrice, err := storer.MidpointPrice() | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
Expect(emptyPrice.Equals(oracle.MidpointPrice{})).Should(BeTrue()) | ||
|
||
price := testutils.RandMidpointPrice() | ||
err = storer.PutMidpointPrice(price) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
|
||
storedPrice, err := storer.MidpointPrice() | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
Expect(price.Equals(storedPrice)).Should(BeTrue()) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1 @@ | ||
package oracle_test | ||
|
||
import ( | ||
"math/rand" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
. "github.com/republicprotocol/republic-go/oracle" | ||
"github.com/republicprotocol/republic-go/testutils" | ||
) | ||
|
||
func init() { | ||
rand.Seed(time.Now().UnixNano()) | ||
} | ||
|
||
var _ = Describe("MidpointPrice storage", func() { | ||
|
||
Context("when storing and retrieving data", func() { | ||
|
||
It("should be able to get the right data we store", func() { | ||
storer := NewMidpointPriceStorer() | ||
emptyPrice, err := storer.MidpointPrice() | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
Expect(emptyPrice.Equals(MidpointPrice{})).Should(BeTrue()) | ||
|
||
price := testutils.RandMidpointPrice() | ||
err = storer.PutMidpointPrice(price) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
|
||
storedPrice, err := storer.MidpointPrice() | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
Expect(price.Equals(storedPrice)).Should(BeTrue()) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters