Skip to content

Commit

Permalink
# This is a combination of 35 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

adds account base impl.

# This is the commit message #2:

fixes SendTrytes() returning reversed bundle

let DoPoW() return trytes in bundle order

fixes AttachToTangle reversing already reversed trytes

# This is the commit message #3:

adds base implementation

# This is the commit message #4:

adds some todos

# This is the commit message #5:

makes addPendingTransfer also store the spent address indices, removes action channels by only using one, adds multi send, removes LastDepositAddress()

# This is the commit message #6:

moves account package

# This is the commit message #7:

adds clean shutdown, precomputed next dep. address, errors channel for internal errors

# This is the commit message #8:

changes state schema, adds promotion/reattachment

# This is the commit message #9:

smh

# This is the commit message #10:

adds deposit requests/conditions

# This is the commit message #11:

fixes tests

# This is the commit message #12:

split packages, make badger use gob instead of json

# This is the commit message #13:

removes SendMulti, makes Send take a variadic parameter

# This is the commit message #14:

fixes tests, reduces to single Send function, splits top level account files

# This is the commit message #15:

implements quorum based querying of nodes

# This is the commit message #16:

switch to xxhash for res body, make primary node optional

# This is the commit message #17:

moves generating hash before lock

# This is the commit message #18:

adds no response tolerance to quorum settings

# This is the commit message #19:

subtract error count from total votes

# This is the commit message #20:

fixes no-response tolerance, adds more descriptive error message

# This is the commit message #21:

adds override for commands to execute in quorum

# This is the commit message #22:

adds quorumable latest subtangle milestone query

# This is the commit message #23:

adds customizable defaults for certain calls where no quorum was reached

# This is the commit message #24:

simplify injectDefault

# This is the commit message #25:

adds partial test

# This is the commit message #26:

fixes some typos, adds additional test for explicit error responses

# This is the commit message #27:

adds UsableBalance()/TotalBalance()

# This is the commit message #28:

refactor input selection, wrap errors with more descriptive messages

# This is the commit message #29:

adds specific checks when querying the latest solid subtangle milestone

# This is the commit message #30:

fixes typo

# This is the commit message #31:

adds safe component update to account, adds special treatment for quorum findTransactions call

# This is the commit message #32:

fixes non receive events to be not fired until first poll went through

# This is the commit message #33:

modulerizes events out of the account object, adds builder pattern for creating accounts and event listeners

# This is the commit message #34:

changes store interface to return maps, optimizes pertail receive event filter, optimizes event listener registration

# This is the commit message #35:

adds correct addr gen. cancellation,fixes receive events being dropped, fixes duplicated receive events for messages
  • Loading branch information
luca-moser committed Jan 30, 2019
1 parent d329639 commit 001fe98
Show file tree
Hide file tree
Showing 22 changed files with 1,983 additions and 804 deletions.
1,267 changes: 704 additions & 563 deletions account/account.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion account/account_suite_test.go
Expand Up @@ -9,5 +9,5 @@ import (

func TestAccount(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Account Suite")
RunSpecs(t, "account Suite")
}
29 changes: 15 additions & 14 deletions account/account_test.go
Expand Up @@ -23,11 +23,11 @@ const usedSecLvl = consts.SecurityLevelLow

type fakeclock struct{}

func (fc *fakeclock) Now() time.Time {
return time.Date(2018, time.November, 22, 21, 53, 0, 0, time.UTC)
func (fc *fakeclock) Now() (time.Time, error) {
return time.Date(2018, time.November, 22, 21, 53, 0, 0, time.UTC), nil
}

var _ = Describe("Account", func() {
var _ = Describe("account", func() {
api, err := ComposeAPI(HTTPClientSettings{}, nil)
if err != nil {
panic(err)
Expand Down Expand Up @@ -59,12 +59,13 @@ var _ = Describe("Account", func() {
"LUENADZTQWWUQ9P9EXINSJJVNZLYVARHYMEY9QMNFZNF9IVMBBMKGUBSZPNMTEMMKVWTMUVLQUBHCHHHX",
}

var acc *account.Account
var acc *account.account
var st *store.InMemoryStore

newAccount := func() {
st = store.NewInMemoryStore()
acc, err = account.NewAccount(seed, st, api, &account.AccountsOpts{
acc, err := acco
acc, err = account.NewAccount(seed, st, api, &account.Settings{
Depth: 3, MWM: 9, SecurityLevel: usedSecLvl, Clock: &fakeclock{},
})
if err != nil {
Expand All @@ -75,7 +76,7 @@ var _ = Describe("Account", func() {
Context("account creation", func() {
It("successfully creates accounts given valid parameters/options", func() {
var err error
acc, err = account.NewAccount(seed, store.NewInMemoryStore(), api, &account.AccountsOpts{
acc, err = account.NewAccount(seed, store.NewInMemoryStore(), api, &account.Settings{
Depth: 3, MWM: 9, SecurityLevel: usedSecLvl,
})
Expect(err).ToNot(HaveOccurred())
Expand All @@ -101,10 +102,10 @@ var _ = Describe("Account", func() {
})

Context("Operations", func() {
Context("Balance()", func() {
Context("UsableBalance()", func() {
BeforeEach(newAccount)

It("returns the correct balance", func() {
It("returns the correct usableBalance", func() {
defer gock.Flush()
balances := []string{"10", "20", "30"}
for i := 0; i < 3; i++ {
Expand All @@ -129,13 +130,13 @@ var _ = Describe("Account", func() {
_, err := acc.NewDepositRequest(&deposit.Request{TimeoutOn: &t})
Expect(err).ToNot(HaveOccurred())
}
balance, err := acc.Balance()
balance, err := acc.UsableBalance()
Expect(err).ToNot(HaveOccurred())
Expect(balance).To(Equal(uint64(60)))
})

It("returns the 0 balance on a new account", func() {
balance, err := acc.Balance()
It("returns the 0 usableBalance on a new account", func() {
balance, err := acc.UsableBalance()
Expect(err).ToNot(HaveOccurred())
Expect(balance).To(Equal(uint64(0)))
})
Expand Down Expand Up @@ -165,7 +166,7 @@ var _ = Describe("Account", func() {
trunkTx := strings.Repeat("A", 81)
branchTx := strings.Repeat("B", 81)

// balance query
// usableBalance query
defer gock.Flush()
gock.New(DefaultLocalIRIURI).
Persist().
Expand Down Expand Up @@ -234,8 +235,8 @@ var _ = Describe("Account", func() {
_, err = acc.NewDepositRequest(&deposit.Request{TimeoutOn: &t, ExpectedAmount: &expectedAmount})
Expect(err).ToNot(HaveOccurred())

By("having the correct current balance")
balance, err := acc.Balance()
By("having the correct current usableBalance")
balance, err := acc.UsableBalance()
Expect(err).ToNot(HaveOccurred())
Expect(balance).To(Equal(uint64(100)))

Expand Down
28 changes: 28 additions & 0 deletions account/deposit/deposit.go
Expand Up @@ -3,6 +3,9 @@ package deposit
import (
"fmt"
. "github.com/iotaledger/iota.go/trinary"
"github.com/pkg/errors"
"net/url"
"strconv"
"time"
)

Expand All @@ -23,6 +26,31 @@ func (dc *Conditions) URL() string {
return fmt.Sprintf("iota://%s/?t=%d&m=%v&am=%d", dc.Address, dc.TimeoutOn.Unix(), dc.MultiUse, dc.ExpectedAmount)
}

func ParseMagnetLink(s string) (*Conditions, error) {
link, err := url.Parse(s)
if err != nil {
return nil, err
}
query := link.Query()
cond := &Conditions{
Address: link.Host,
}
expiresSeconds, err := strconv.ParseInt(query.Get(ConditionExpires), 10, 64)
if err != nil {
return nil, errors.Wrap(err, "invalid expire timestamp")
}
expire := time.Unix(expiresSeconds, 0)
cond.TimeoutOn = &expire
cond.MultiUse = query.Get(ConditionMultiUse) == "true"
expectedAmount, err := strconv.ParseInt(query.Get(ConditionAmount), 10, 64)
if err != nil {
return nil, errors.Wrap(err, "invalid expected amount")
}
expectedAmountUint := uint64(expectedAmount)
cond.ExpectedAmount = &expectedAmountUint
return cond, nil
}

// Request defines a new deposit request against the account.
type Request struct {
// The timeout after this deposit address becomes invalid (creation+timeout)
Expand Down
1 change: 1 addition & 0 deletions account/errors.go
Expand Up @@ -25,3 +25,4 @@ func (err ErrAccountPanic) Error() string {

var ErrTimeoutNotSpecified = errors.New("deposit requests must have a timeout")
var ErrTimeoutTooLow = errors.New("deposit requests must at least have a timeout of >2 minutes")
var ErrAddrGeneratorStopped = errors.New("address generator goroutine is stopped")

0 comments on commit 001fe98

Please sign in to comment.