-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bnsd: allow for a zero fee for preregistation record msg (#1151)
A new preregistration decorator was added to `bnsd`. When `bnsd` is configured correctly the newly added decorator allows for submitting `preregistration.RegisterMsg` without any fee. resolve #1143
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 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,60 @@ | ||
package preregistration | ||
|
||
import ( | ||
weave "github.com/iov-one/weave" | ||
"github.com/iov-one/weave/coin" | ||
"github.com/iov-one/weave/errors" | ||
) | ||
|
||
// NewZeroFeeDecorator returns a decorator that lowers the fee for a record | ||
// preregistration message. | ||
func NewZeroFeeDecorator() *ZeroFeeDecorator { | ||
return &ZeroFeeDecorator{} | ||
} | ||
|
||
// ZeroFeeDecorator zero fee for a transaction that contains a single message | ||
// of registering a preregistration record. Preregistration records can be | ||
// inserted only by an admin, so even the antispam fee is not necessary. | ||
type ZeroFeeDecorator struct{} | ||
|
||
var _ weave.Decorator = (*ZeroFeeDecorator)(nil) | ||
|
||
func (*ZeroFeeDecorator) Check(ctx weave.Context, store weave.KVStore, tx weave.Tx, next weave.Checker) (*weave.CheckResult, error) { | ||
res, err := next.Check(ctx, store, tx) | ||
if err != nil { | ||
return res, err | ||
} | ||
if res.RequiredFee.IsZero() { | ||
return res, err | ||
} | ||
|
||
msg, err := tx.GetMsg() | ||
if err != nil { | ||
return nil, errors.Wrap(err, "cannot unpack transaction message") | ||
} | ||
if _, ok := msg.(*RegisterMsg); ok { | ||
// Zero the fee. | ||
res.RequiredFee = coin.Coin{} | ||
} | ||
return res, nil | ||
} | ||
|
||
func (*ZeroFeeDecorator) Deliver(ctx weave.Context, store weave.KVStore, tx weave.Tx, next weave.Deliverer) (*weave.DeliverResult, error) { | ||
res, err := next.Deliver(ctx, store, tx) | ||
if err != nil { | ||
return res, err | ||
} | ||
if res.RequiredFee.IsZero() { | ||
return res, err | ||
} | ||
|
||
msg, err := tx.GetMsg() | ||
if err != nil { | ||
return nil, errors.Wrap(err, "cannot unpack transaction message") | ||
} | ||
if _, ok := msg.(*RegisterMsg); ok { | ||
// Zero the fee. | ||
res.RequiredFee = coin.Coin{} | ||
} | ||
return res, nil | ||
} |