Skip to content

Commit

Permalink
payments: factional amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
aastein authored Jul 16, 2018
1 parent ff3298d commit 2577d97
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 39 deletions.
14 changes: 7 additions & 7 deletions _docs/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ profiles:
attributes:
region: us-west
pricing:
web: 8m
db-master: 15A
db-slave: 10A
db-pool: 5A
web: .8
db-master: 15
db-slave: 10
db-pool: 5
eastcoast:
attributes:
region: us-east
pricing:
web: 5A
db-slave: 10A
db-pool: 5A
web: .5
db-slave: 10
db-pool: 5

deployment:

Expand Down
6 changes: 3 additions & 3 deletions _integration/cmp/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func accountBalance(key key, amount int64) gestalt.Component {

func accountSendTo(from key, to key, amount int64) gestalt.Component {
return akash("send-to",
"send", strconv.FormatInt(amount, 10)+"m", to.addr.Var(), "-k", from.name.Name()).
"send", strconv.FormatInt(amount, 10), to.addr.Var(), "-k", from.name.Name()).
WithMeta(g.Require(to.addr.Name()))
}

Expand All @@ -32,6 +32,6 @@ func groupAccountSend(key key) gestalt.Component {
Run(accountBalance(key, start)).
Run(accountSendTo(key, other, amount)).
Run(g.Retry(5).
Run(accountBalance(key, start-amount))).
Run(accountBalance(other, amount))
Run(accountBalance(key, start-1000*amount))).
Run(accountBalance(other, 1000*amount))
}
2 changes: 1 addition & 1 deletion _run/kube/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ profiles:
attributes:
region: us-west
pricing:
web: 100m
web: .101

deployment:
web:
Expand Down
2 changes: 1 addition & 1 deletion _run/multi/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ profiles:
attributes:
region: us-west
pricing:
web: 100m
web: .1

deployment:
web:
Expand Down
31 changes: 6 additions & 25 deletions denom/denom.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
package denom

import (
"fmt"
"strconv"
"strings"
)

const (
miliAkash = 1
Akash = 1000 * miliAkash
miliAkashPerAkash = 1000
)

var unitSuffixes = []struct {
symbol string
unit uint64
}{
{"A", Akash},
{"m", miliAkash},
}

// ToBase converts a unit of currency to its equivalent value in base denomination
func ToBase(sval string) (uint64, error) {
for _, suffix := range unitSuffixes {
if !strings.HasSuffix(sval, suffix.symbol) {
continue
}
sval := strings.TrimSuffix(sval, suffix.symbol)
val, err := strconv.ParseUint(sval, 10, 64)
if err != nil {
return 0, err
}
amount := val * suffix.unit
return amount, nil
akash, err := strconv.ParseFloat(sval, 64)
if err != nil {
return 0, err
}

return 0, fmt.Errorf("unrecognized denomination %s", sval)
amount := akash * miliAkashPerAkash
return uint64(amount), nil
}
2 changes: 1 addition & 1 deletion sdl/_testdata/simple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ profiles:
attributes:
region: us-west
pricing:
web: 8m
web: .8

deployment:
web:
Expand Down
2 changes: 1 addition & 1 deletion sdl/v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func Test_v1_Parse_simple(t *testing.T) {

assert.Equal(t, types.ResourceGroup{
Count: 20,
Price: 8,
Price: 800,
Unit: types.ResourceUnit{
CPU: 2000,
Memory: 128 * uint64(math.Pow(1024, 2)),
Expand Down

0 comments on commit 2577d97

Please sign in to comment.