Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEMO: don't merge] Simple context #835

Closed
wants to merge 17 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed all remaining compiler errors
ethanfrey committed Jun 27, 2019
commit 08a94a5126e68ef6b4210cb673843f7c89e2ee53
4 changes: 1 addition & 3 deletions cmd/bnsd/app/app.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ to construct the bnsd app.
package bnsd

import (
"context"
"fmt"
"path/filepath"
"strings"
@@ -124,12 +123,11 @@ func Stack(issuer weave.Address, minFee coin.Coin) weave.Handler {
func Application(name string, h weave.Handler,
tx weave.TxDecoder, dbPath string, options *server.Options) (app.BaseApp, error) {

ctx := context.Background()
kv, err := CommitKVStore(dbPath)
if err != nil {
return app.BaseApp{}, err
}
store := app.NewStoreApp(name, kv, QueryRouter(options.MinFee), ctx)
store := app.NewStoreApp(name, kv, QueryRouter(options.MinFee))
base := app.NewBaseApp(store, tx, h, nil, options.Debug)
return base, nil
}
4 changes: 1 addition & 3 deletions cmd/bnsd/app/init.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package bnsd

import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
@@ -112,8 +111,7 @@ func DecorateApp(application app.BaseApp, logger log.Logger) app.BaseApp {
func InlineApp(kv weave.CommitKVStore, logger log.Logger, debug bool) abci.Application {
minFee := coin.Coin{}
stack := Stack(nil, minFee)
ctx := context.Background()
store := app.NewStoreApp("bnsd", kv, QueryRouter(minFee), ctx)
store := app.NewStoreApp("bnsd", kv, QueryRouter(minFee))
base := app.NewBaseApp(store, TxDecoder, stack, nil, debug)
return DecorateApp(base, logger)
}
16 changes: 8 additions & 8 deletions x/aswap/handler.go
Original file line number Diff line number Diff line change
@@ -121,7 +121,7 @@ var _ weave.Handler = ReleaseSwapHandler{}
// Check just verifies it is properly formed and returns
// the cost of executing it
func (h ReleaseSwapHandler) Check(ctx context.Context, info weave.BlockInfo, db weave.KVStore, tx weave.Tx) (*weave.CheckResult, error) {
_, _, err := h.validate(ctx, db, tx)
_, _, err := h.validate(ctx, info, db, tx)
if err != nil {
return nil, err
}
@@ -132,7 +132,7 @@ func (h ReleaseSwapHandler) Check(ctx context.Context, info weave.BlockInfo, db
// Deliver moves the tokens from swap account to the receiver if
// all preconditions are met. When the swap account is empty it is deleted.
func (h ReleaseSwapHandler) Deliver(ctx context.Context, info weave.BlockInfo, db weave.KVStore, tx weave.Tx) (*weave.DeliverResult, error) {
swapID, swap, err := h.validate(ctx, db, tx)
swapID, swap, err := h.validate(ctx, info, db, tx)
if err != nil {
return nil, err
}
@@ -158,7 +158,7 @@ func (h ReleaseSwapHandler) Deliver(ctx context.Context, info weave.BlockInfo, d
}

// validate does all common pre-processing between Check and Deliver.
func (h ReleaseSwapHandler) validate(ctx context.Context, db weave.KVStore, tx weave.Tx) ([]byte, *Swap, error) {
func (h ReleaseSwapHandler) validate(ctx context.Context, info weave.BlockInfo, db weave.KVStore, tx weave.Tx) ([]byte, *Swap, error) {
var msg ReleaseMsg
if err := weave.LoadMsg(tx, &msg); err != nil {
return nil, nil, errors.Wrap(err, "load msg")
@@ -175,7 +175,7 @@ func (h ReleaseSwapHandler) validate(ctx context.Context, db weave.KVStore, tx w
return nil, nil, errors.Wrap(errors.ErrUnauthorized, "invalid preimageHash")
}

if weave.IsExpired(ctx, swap.Timeout) {
if info.IsExpired(swap.Timeout) {
return nil, nil, errors.Wrap(errors.ErrState, "swap is expired")
}

@@ -194,7 +194,7 @@ var _ weave.Handler = ReturnSwapHandler{}
// Check just verifies it is properly formed and returns
// the cost of executing it.
func (h ReturnSwapHandler) Check(ctx context.Context, info weave.BlockInfo, db weave.KVStore, tx weave.Tx) (*weave.CheckResult, error) {
_, _, err := h.validate(ctx, db, tx)
_, _, err := h.validate(ctx, info, db, tx)
if err != nil {
return nil, err
}
@@ -205,7 +205,7 @@ func (h ReturnSwapHandler) Check(ctx context.Context, info weave.BlockInfo, db w
// Deliver moves all the tokens from the swap to the defined sender if
// all preconditions are met. The swap is deleted afterwards.
func (h ReturnSwapHandler) Deliver(ctx context.Context, info weave.BlockInfo, db weave.KVStore, tx weave.Tx) (*weave.DeliverResult, error) {
msg, swap, err := h.validate(ctx, db, tx)
msg, swap, err := h.validate(ctx, info, db, tx)
if err != nil {
return nil, err
}
@@ -229,7 +229,7 @@ func (h ReturnSwapHandler) Deliver(ctx context.Context, info weave.BlockInfo, db
}

// validate does all common pre-processing between Check and Deliver.
func (h ReturnSwapHandler) validate(ctx context.Context, db weave.KVStore, tx weave.Tx) (*ReturnSwapMsg, *Swap, error) {
func (h ReturnSwapHandler) validate(ctx context.Context, info weave.BlockInfo, db weave.KVStore, tx weave.Tx) (*ReturnSwapMsg, *Swap, error) {
var msg ReturnSwapMsg
if err := weave.LoadMsg(tx, &msg); err != nil {
return nil, nil, errors.Wrap(err, "load msg")
@@ -240,7 +240,7 @@ func (h ReturnSwapHandler) validate(ctx context.Context, db weave.KVStore, tx we
return nil, nil, err
}

if !weave.IsExpired(ctx, swap.Timeout) {
if !info.IsExpired(swap.Timeout) {
return nil, nil, errors.Wrapf(errors.ErrState, "swap not expired %v", swap.Timeout)
}

32 changes: 16 additions & 16 deletions x/escrow/handler.go
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ var _ weave.Handler = CreateEscrowHandler{}
// Check just verifies it is properly formed and returns
// the cost of executing it.
func (h CreateEscrowHandler) Check(ctx context.Context, info weave.BlockInfo, db weave.KVStore, tx weave.Tx) (*weave.CheckResult, error) {
_, err := h.validate(ctx, db, tx)
_, err := h.validate(ctx, info, db, tx)
if err != nil {
return nil, err
}
@@ -63,7 +63,7 @@ func (h CreateEscrowHandler) Check(ctx context.Context, info weave.BlockInfo, db
// Deliver moves the tokens from sender to the escrow account if
// all preconditions are met.
func (h CreateEscrowHandler) Deliver(ctx context.Context, info weave.BlockInfo, db weave.KVStore, tx weave.Tx) (*weave.DeliverResult, error) {
msg, err := h.validate(ctx, db, tx)
msg, err := h.validate(ctx, info, db, tx)
if err != nil {
return nil, err
}
@@ -102,13 +102,13 @@ func (h CreateEscrowHandler) Deliver(ctx context.Context, info weave.BlockInfo,
}

// validate does all common pre-processing between Check and Deliver.
func (h CreateEscrowHandler) validate(ctx context.Context, db weave.KVStore, tx weave.Tx) (*CreateMsg, error) {
func (h CreateEscrowHandler) validate(ctx context.Context, info weave.BlockInfo, db weave.KVStore, tx weave.Tx) (*CreateMsg, error) {
var msg CreateMsg
if err := weave.LoadMsg(tx, &msg); err != nil {
return nil, errors.Wrap(err, "load msg")
}

if weave.IsExpired(ctx, msg.Timeout) {
if info.IsExpired(msg.Timeout) {
return nil, errors.Wrap(errors.ErrInput, "timeout in the past")
}

@@ -134,7 +134,7 @@ var _ weave.Handler = ReleaseEscrowHandler{}
// Check just verifies it is properly formed and returns
// the cost of executing it
func (h ReleaseEscrowHandler) Check(ctx context.Context, info weave.BlockInfo, db weave.KVStore, tx weave.Tx) (*weave.CheckResult, error) {
_, _, err := h.validate(ctx, db, tx)
_, _, err := h.validate(ctx, info, db, tx)
if err != nil {
return nil, err
}
@@ -145,7 +145,7 @@ func (h ReleaseEscrowHandler) Check(ctx context.Context, info weave.BlockInfo, d
// Deliver moves the tokens from escrow account to the receiver if
// all preconditions are met. When the escrow account is empty it is deleted.
func (h ReleaseEscrowHandler) Deliver(ctx context.Context, info weave.BlockInfo, db weave.KVStore, tx weave.Tx) (*weave.DeliverResult, error) {
msg, escrow, err := h.validate(ctx, db, tx)
msg, escrow, err := h.validate(ctx, info, db, tx)
if err != nil {
return nil, err
}
@@ -182,7 +182,7 @@ func (h ReleaseEscrowHandler) Deliver(ctx context.Context, info weave.BlockInfo,
}

// validate does all common pre-processing between Check and Deliver.
func (h ReleaseEscrowHandler) validate(ctx context.Context, db weave.KVStore, tx weave.Tx) (*ReleaseMsg, *Escrow, error) {
func (h ReleaseEscrowHandler) validate(ctx context.Context, info weave.BlockInfo, db weave.KVStore, tx weave.Tx) (*ReleaseMsg, *Escrow, error) {
var msg ReleaseMsg
if err := weave.LoadMsg(tx, &msg); err != nil {
return nil, nil, errors.Wrap(err, "load msg")
@@ -197,7 +197,7 @@ func (h ReleaseEscrowHandler) validate(ctx context.Context, db weave.KVStore, tx
return nil, nil, errors.ErrUnauthorized
}

if weave.IsExpired(ctx, escrow.Timeout) {
if info.IsExpired(escrow.Timeout) {
err := errors.Wrapf(errors.ErrExpired, "escrow expired %v", escrow.Timeout)
return nil, nil, err
}
@@ -217,7 +217,7 @@ var _ weave.Handler = ReturnEscrowHandler{}
// Check just verifies it is properly formed and returns
// the cost of executing it.
func (h ReturnEscrowHandler) Check(ctx context.Context, info weave.BlockInfo, db weave.KVStore, tx weave.Tx) (*weave.CheckResult, error) {
_, _, err := h.validate(ctx, db, tx)
_, _, err := h.validate(ctx, info, db, tx)
if err != nil {
return nil, err
}
@@ -228,7 +228,7 @@ func (h ReturnEscrowHandler) Check(ctx context.Context, info weave.BlockInfo, db
// Deliver moves all the tokens from the escrow to the defined sender if
// all preconditions are met. The escrow is deleted afterwards.
func (h ReturnEscrowHandler) Deliver(ctx context.Context, info weave.BlockInfo, db weave.KVStore, tx weave.Tx) (*weave.DeliverResult, error) {
key, escrow, err := h.validate(ctx, db, tx)
key, escrow, err := h.validate(ctx, info, db, tx)
if err != nil {
return nil, err
}
@@ -251,7 +251,7 @@ func (h ReturnEscrowHandler) Deliver(ctx context.Context, info weave.BlockInfo,
}

// validate does all common pre-processing between Check and Deliver.
func (h ReturnEscrowHandler) validate(ctx context.Context, db weave.KVStore, tx weave.Tx) ([]byte, *Escrow, error) {
func (h ReturnEscrowHandler) validate(ctx context.Context, info weave.BlockInfo, db weave.KVStore, tx weave.Tx) ([]byte, *Escrow, error) {
var msg ReturnMsg
if err := weave.LoadMsg(tx, &msg); err != nil {
return nil, nil, errors.Wrap(err, "load msg")
@@ -262,7 +262,7 @@ func (h ReturnEscrowHandler) validate(ctx context.Context, db weave.KVStore, tx
return nil, nil, err
}

if !weave.IsExpired(ctx, escrow.Timeout) {
if !info.IsExpired(escrow.Timeout) {
return nil, nil, errors.Wrapf(errors.ErrState, "escrow not expired %v", escrow.Timeout)
}

@@ -280,7 +280,7 @@ var _ weave.Handler = UpdateEscrowHandler{}
// Check just verifies it is properly formed and returns
// the cost of executing it.
func (h UpdateEscrowHandler) Check(ctx context.Context, info weave.BlockInfo, db weave.KVStore, tx weave.Tx) (*weave.CheckResult, error) {
_, _, err := h.validate(ctx, db, tx)
_, _, err := h.validate(ctx, info, db, tx)
if err != nil {
return nil, err
}
@@ -291,7 +291,7 @@ func (h UpdateEscrowHandler) Check(ctx context.Context, info weave.BlockInfo, db
// Deliver updates the any of the sender, recipient or arbiter if
// all preconditions are met. No coins are moved.
func (h UpdateEscrowHandler) Deliver(ctx context.Context, info weave.BlockInfo, db weave.KVStore, tx weave.Tx) (*weave.DeliverResult, error) {
msg, escrow, err := h.validate(ctx, db, tx)
msg, escrow, err := h.validate(ctx, info, db, tx)
if err != nil {
return nil, err
}
@@ -317,7 +317,7 @@ func (h UpdateEscrowHandler) Deliver(ctx context.Context, info weave.BlockInfo,
}

// validate does all common pre-processing between Check and Deliver.
func (h UpdateEscrowHandler) validate(ctx context.Context, db weave.KVStore, tx weave.Tx) (*UpdatePartiesMsg, *Escrow, error) {
func (h UpdateEscrowHandler) validate(ctx context.Context, info weave.BlockInfo, db weave.KVStore, tx weave.Tx) (*UpdatePartiesMsg, *Escrow, error) {
var msg UpdatePartiesMsg
if err := weave.LoadMsg(tx, &msg); err != nil {
return nil, nil, errors.Wrap(err, "load msg")
@@ -328,7 +328,7 @@ func (h UpdateEscrowHandler) validate(ctx context.Context, db weave.KVStore, tx
return nil, nil, err
}

if weave.IsExpired(ctx, escrow.Timeout) {
if info.IsExpired(escrow.Timeout) {
return nil, nil, errors.Wrapf(errors.ErrExpired, "escrow expired %v", escrow.Timeout)
}

Loading