From 5f7a63c332b02447e4aa2aced2e1438e2426d342 Mon Sep 17 00:00:00 2001 From: Frojdi Dymylja <33157909+fdymylja@users.noreply.github.com> Date: Tue, 31 Mar 2020 13:06:51 +0200 Subject: [PATCH] revert e311cb3 (#1184) this PR reverts the burn feature implemented in e311cb3 --- CHANGELOG.md | 1 + cmd/bnsd/app/app.go | 2 +- cmd/bnsd/app/cashctrl.go | 51 ----------------------------- cmd/bnsd/app/cashctrl_test.go | 61 ----------------------------------- 4 files changed, 2 insertions(+), 113 deletions(-) delete mode 100644 cmd/bnsd/app/cashctrl.go delete mode 100644 cmd/bnsd/app/cashctrl_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index b2e49e57..c811c2c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## HEAD +- `bnsd`: revert burn feature - `bnsd`: when a domain is transferred accounts ownership is transferred to the new domain owner and accounts' targets are cleared - `bnsapi`: move bnsapi to new repo - `bnscli`: fix boolean flag bug diff --git a/cmd/bnsd/app/app.go b/cmd/bnsd/app/app.go index 21cfbd26..229ca09a 100644 --- a/cmd/bnsd/app/app.go +++ b/cmd/bnsd/app/app.go @@ -76,7 +76,7 @@ func Chain(authFn x.Authenticator, minFee coin.Coin) app.Decorators { // ctrl can be initialized with any implementation, but must be used // consistently everywhere. -var ctrl cash.Controller = BnsCashController(cash.NewController(cash.NewBucket())) +var ctrl = cash.NewController(cash.NewBucket()) // Router returns a default router, only dispatching to the // cash.SendMsg diff --git a/cmd/bnsd/app/cashctrl.go b/cmd/bnsd/app/cashctrl.go deleted file mode 100644 index 5d758b12..00000000 --- a/cmd/bnsd/app/cashctrl.go +++ /dev/null @@ -1,51 +0,0 @@ -package bnsd - -import ( - "bytes" - - "github.com/iov-one/weave" - "github.com/iov-one/weave/coin" - "github.com/iov-one/weave/errors" - "github.com/iov-one/weave/x/cash" -) - -// BnsCashController wraps provided cash controller implementation with -// functionality specific to BNS. -func BnsCashController(c cash.Controller) cash.Controller { - return &CashController{ - b: cash.NewBucket(), - ctrl: c, - } -} - -// CashController is a BNS specific cash.Controller implementation. -type CashController struct { - b cash.Bucket - ctrl cash.Controller -} - -func (c *CashController) MoveCoins(store weave.KVStore, src weave.Address, dest weave.Address, amount coin.Coin) error { - if err := c.ctrl.MoveCoins(store, src, dest, amount); err != nil { - return errors.Wrap(err, "move coins") - } - if dest.Equals(burnWallet) { - empty := cash.NewWallet(burnWallet) - if err := c.b.Save(store, empty); err != nil { - return errors.Wrap(err, "cannot flush burn wallet") - } - } - return nil -} - -// Burn wallet as requested in https://github.com/iov-one/weave/issues/1140 -// -// Any funds send to this wallet should be instantly removed from the system. -// This can be achieved by making sure that the wallet is always empty and even -// if any funds were sent to it, flush it instantly. -// -// This address is represented by iov1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqvnwh0u -var burnWallet = weave.Address(bytes.Repeat([]byte{0}, weave.AddressLength)) - -func (c *CashController) Balance(db weave.KVStore, a weave.Address) (coin.Coins, error) { - return c.ctrl.Balance(db, a) -} diff --git a/cmd/bnsd/app/cashctrl_test.go b/cmd/bnsd/app/cashctrl_test.go deleted file mode 100644 index ba5325d0..00000000 --- a/cmd/bnsd/app/cashctrl_test.go +++ /dev/null @@ -1,61 +0,0 @@ -package bnsd - -import ( - "bytes" - "testing" - - "github.com/iov-one/weave" - "github.com/iov-one/weave/coin" - "github.com/iov-one/weave/migration" - "github.com/iov-one/weave/store" - "github.com/iov-one/weave/weavetest" - "github.com/iov-one/weave/x/cash" -) - -func TestBnsCashController(t *testing.T) { - db := store.MemStore() - migration.MustInitPkg(db, "cash") - var ( - alice = weavetest.NewCondition().Address() - bob = weavetest.NewCondition().Address() - burn = weave.Address(bytes.Repeat([]byte{0}, weave.AddressLength)) - ) - - ctrl := cash.NewController(cash.NewBucket()) - if err := ctrl.CoinMint(db, alice, coin.NewCoin(100, 0, "IOV")); err != nil { - t.Fatalf("mint: %s", err) - } - - bnsCtrl := BnsCashController(ctrl) - - if err := bnsCtrl.MoveCoins(db, alice, bob, coin.NewCoin(10, 0, "IOV")); err != nil { - t.Fatalf("transfer from alice to bob: %s", err) - } - - if funds, err := bnsCtrl.Balance(db, alice); err != nil { - t.Fatalf("alice balance: %s", err) - } else if !funds.Equals(coin.Coins{coin.NewCoinp(90, 0, "IOV")}) { - t.Fatalf("want 90 IOV, got %v", funds) - } - - if funds, err := bnsCtrl.Balance(db, bob); err != nil { - t.Fatalf("bob balance: %s", err) - } else if !funds.Equals(coin.Coins{coin.NewCoinp(10, 0, "IOV")}) { - t.Fatalf("want 10 IOV, got %v", funds) - } - - // Sending to a burn wallet must remove coins from the system. - if err := bnsCtrl.MoveCoins(db, alice, burn, coin.NewCoin(30, 0, "IOV")); err != nil { - t.Fatalf("transfer from alice to burn: %s", err) - } - if funds, err := bnsCtrl.Balance(db, alice); err != nil { - t.Fatalf("alice balance: %s", err) - } else if !funds.Equals(coin.Coins{coin.NewCoinp(60, 0, "IOV")}) { - t.Fatalf("want 60 IOV, got %v", funds) - } - if funds, err := bnsCtrl.Balance(db, burn); err != nil { - t.Fatalf("alice balance: %s", err) - } else if !funds.Equals(coin.Coins{}) { - t.Fatalf("want empty wallet, got %v", funds) - } -}