Skip to content

Commit

Permalink
balance: drop unused Mint/Burn notifications, fix #318
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Khimov <roman@nspcc.ru>
  • Loading branch information
roman-khimov committed Sep 25, 2023
1 parent d2f3761 commit 879e3ce
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 182 deletions.
6 changes: 2 additions & 4 deletions balance/balance_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func NewEpoch(epochNum int) {
// Mint is a method that transfers assets to a user account from an empty account.
// It can be invoked only by Alphabet nodes of the Inner Ring.
//
// It produces Mint, Transfer and TransferX notifications.
// It produces Transfer and TransferX notifications.
//
// Mint method is invoked by Alphabet nodes of the Inner Ring when they process
// Deposit notification from NeoFS contract. Before that, Alphabet nodes should
Expand All @@ -272,13 +272,12 @@ func Mint(to interop.Hash160, amount int, txDetails []byte) {
supply = supply + amount
storage.Put(ctx, token.CirculationKey, supply)
runtime.Log("assets were minted")
runtime.Notify("Mint", to, amount)
}

// Burn is a method that transfers assets from a user account to an empty account.
// It can be invoked only by Alphabet nodes of the Inner Ring.
//
// It produces Burn, Transfer and TransferX notifications.
// It produces Transfer and TransferX notifications.
//
// Burn method is invoked by Alphabet nodes of the Inner Ring when they process
// Cheque notification from NeoFS contract. It means that locked assets have been
Expand Down Expand Up @@ -307,7 +306,6 @@ func Burn(from interop.Hash160, amount int, txDetails []byte) {
supply = supply - amount
storage.Put(ctx, token.CirculationKey, supply)
runtime.Log("assets were burned")
runtime.Notify("Burn", from, amount)
}

// Version returns the version of the contract.
Expand Down
12 changes: 0 additions & 12 deletions balance/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,3 @@ events:
type: Integer
- name: details
type: ByteArray
- name: Mint
parameters:
- name: to
type: Hash160
- name: amount
type: Integer
- name: Burn
parameters:
- name: from
type: Hash160
- name: amount
type: Integer
18 changes: 0 additions & 18 deletions balance/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,6 @@ Cheque method invocation of NeoFS contract.
type: Integer
- name: until
type: Integer
Mint notification. This notification is produced when user balance is
replenished from deposit in the mainchain.
Mint:
- name: to
type: Hash160
- name: amount
type: Integer
Burn notification. This notification is produced after user balance is reduced
when NeoFS contract has transferred GAS assets back to the user.
Burn:
- name: from
type: Hash160
- name: amount
type: Integer
*/
package balance

Expand Down
148 changes: 0 additions & 148 deletions rpc/balance/rpcbinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,6 @@ type TransferXEvent struct {
Details []byte
}

// MintEvent represents "Mint" event emitted by the contract.
type MintEvent struct {
To util.Uint160
Amount *big.Int
}

// BurnEvent represents "Burn" event emitted by the contract.
type BurnEvent struct {
From util.Uint160
Amount *big.Int
}

// Invoker is used by ContractReader to call various safe methods.
type Invoker interface {
nep17.Invoker
Expand Down Expand Up @@ -1934,139 +1922,3 @@ func (e *TransferXEvent) FromStackItem(item *stackitem.Array) error {

return nil
}

// MintEventsFromApplicationLog retrieves a set of all emitted events
// with "Mint" name from the provided [result.ApplicationLog].
func MintEventsFromApplicationLog(log *result.ApplicationLog) ([]*MintEvent, error) {
if log == nil {
return nil, errors.New("nil application log")
}

var res []*MintEvent
for i, ex := range log.Executions {
for j, e := range ex.Events {
if e.Name != "Mint" {
continue
}
event := new(MintEvent)
err := event.FromStackItem(e.Item)
if err != nil {
return nil, fmt.Errorf("failed to deserialize MintEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
}
res = append(res, event)
}
}

return res, nil
}

// FromStackItem converts provided [stackitem.Array] to MintEvent or
// returns an error if it's not possible to do to so.
func (e *MintEvent) FromStackItem(item *stackitem.Array) error {
if item == nil {
return errors.New("nil item")
}
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return errors.New("not an array")
}
if len(arr) != 2 {
return errors.New("wrong number of structure elements")
}

var (
index = -1
err error
)
index++
e.To, err = func (item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes()
if err != nil {
return util.Uint160{}, err
}
u, err := util.Uint160DecodeBytesBE(b)
if err != nil {
return util.Uint160{}, err
}
return u, nil
} (arr[index])
if err != nil {
return fmt.Errorf("field To: %w", err)
}

index++
e.Amount, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Amount: %w", err)
}

return nil
}

// BurnEventsFromApplicationLog retrieves a set of all emitted events
// with "Burn" name from the provided [result.ApplicationLog].
func BurnEventsFromApplicationLog(log *result.ApplicationLog) ([]*BurnEvent, error) {
if log == nil {
return nil, errors.New("nil application log")
}

var res []*BurnEvent
for i, ex := range log.Executions {
for j, e := range ex.Events {
if e.Name != "Burn" {
continue
}
event := new(BurnEvent)
err := event.FromStackItem(e.Item)
if err != nil {
return nil, fmt.Errorf("failed to deserialize BurnEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
}
res = append(res, event)
}
}

return res, nil
}

// FromStackItem converts provided [stackitem.Array] to BurnEvent or
// returns an error if it's not possible to do to so.
func (e *BurnEvent) FromStackItem(item *stackitem.Array) error {
if item == nil {
return errors.New("nil item")
}
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return errors.New("not an array")
}
if len(arr) != 2 {
return errors.New("wrong number of structure elements")
}

var (
index = -1
err error
)
index++
e.From, err = func (item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes()
if err != nil {
return util.Uint160{}, err
}
u, err := util.Uint160DecodeBytesBE(b)
if err != nil {
return util.Uint160{}, err
}
return u, nil
} (arr[index])
if err != nil {
return fmt.Errorf("field From: %w", err)
}

index++
e.Amount, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Amount: %w", err)
}

return nil
}

0 comments on commit 879e3ce

Please sign in to comment.