Skip to content

Commit 00d5d10

Browse files
committed
wip
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
1 parent 4844514 commit 00d5d10

6 files changed

Lines changed: 292 additions & 193 deletions

File tree

pkg/innerring/internal/metachain/contracts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewCustomNatives(cfg neogoconfig.ProtocolConfiguration) []interop.Contract
4949
neoContract = contract.(native.INEO)
5050
newContracts = append(newContracts, neoContract)
5151
case *native.GAS:
52-
newContracts = append(newContracts, gas.NewGAS(int64(cfg.InitialGASSupply)))
52+
newContracts = append(newContracts, gas.NewGAS())
5353
case *native.Management, *native.Ledger, *native.Policy, *native.Designate, *native.Notary:
5454
newContracts = append(newContracts, contract)
5555
case *native.Std, *native.Crypto, *native.Oracle, *native.Treasury:
Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package gas
22

33
import (
4-
"errors"
54
"math/big"
65

76
"github.com/nspcc-dev/neo-go/pkg/config"
@@ -10,28 +9,24 @@ import (
109
"github.com/nspcc-dev/neo-go/pkg/core/native"
1110
"github.com/nspcc-dev/neo-go/pkg/core/native/nativeids"
1211
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
13-
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
14-
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
15-
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
1612
"github.com/nspcc-dev/neo-go/pkg/util"
1713
)
1814

1915
// DefaultBalance is a balance of every account in redefined [GAS] native
2016
// contract.
2117
const DefaultBalance = 100
2218

19+
var _ = (native.IGAS)(&GAS{})
20+
2321
// GAS represents GAS custom native contract. It always returns [DefaultBalance] as a
2422
// balance, has no-op `Burn`, `Mint`, `Transfer` operations.
2523
type GAS struct {
2624
nep17TokenNative
27-
initialSupply int64
2825
}
2926

3027
// NewGAS returns [GAS] custom native contract.
31-
func NewGAS(init int64) *GAS {
32-
g := &GAS{
33-
initialSupply: init,
34-
}
28+
func NewGAS() *GAS {
29+
g := &GAS{}
3530
defer g.BuildHFSpecificMD(g.ActiveIn())
3631

3732
nep17 := newNEP17Native(nativenames.Gas, nativeids.GasToken, nil)
@@ -46,22 +41,6 @@ func NewGAS(init int64) *GAS {
4641

4742
// Initialize initializes a GAS contract.
4843
func (g *GAS) Initialize(ic *interop.Context, hf *config.Hardfork, newMD *interop.HFSpecificContractMD) error {
49-
if hf != g.ActiveIn() {
50-
return nil
51-
}
52-
53-
if err := g.nep17TokenNative.Initialize(ic); err != nil {
54-
return err
55-
}
56-
_, totalSupply := g.getTotalSupply(ic.DAO)
57-
if totalSupply.Sign() != 0 {
58-
return errors.New("already initialized")
59-
}
60-
h, err := getStandbyValidatorsHash(ic)
61-
if err != nil {
62-
return err
63-
}
64-
g.Mint(ic, h, big.NewInt(g.initialSupply), false)
6544
return nil
6645
}
6746

@@ -89,16 +68,3 @@ func (g *GAS) ActiveIn() *config.Hardfork {
8968
func (g *GAS) BalanceOf(d *dao.Simple, acc util.Uint160) *big.Int {
9069
return g.balanceOfInternal(d, acc)
9170
}
92-
93-
func getStandbyValidatorsHash(ic *interop.Context) (util.Uint160, error) {
94-
cfg := ic.Chain.GetConfig()
95-
committee, err := keys.NewPublicKeysFromStrings(cfg.StandbyCommittee)
96-
if err != nil {
97-
return util.Uint160{}, err
98-
}
99-
s, err := smartcontract.CreateDefaultMultiSigRedeemScript(committee[:cfg.GetNumOfCNs(0)])
100-
if err != nil {
101-
return util.Uint160{}, err
102-
}
103-
return hash.Hash160(s), nil
104-
}

pkg/innerring/internal/metachain/gas/nep17.go

Lines changed: 13 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"github.com/nspcc-dev/neo-go/pkg/core/dao"
88
"github.com/nspcc-dev/neo-go/pkg/core/interop"
99
"github.com/nspcc-dev/neo-go/pkg/core/native"
10-
"github.com/nspcc-dev/neo-go/pkg/core/state"
11-
"github.com/nspcc-dev/neo-go/pkg/encoding/bigint"
1210
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
1311
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
1412
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
@@ -24,9 +22,6 @@ type nep17TokenNative struct {
2422
factor int64
2523
}
2624

27-
// totalSupplyKey is the key used to store totalSupply value.
28-
var totalSupplyKey = []byte{11}
29-
3025
func (c *nep17TokenNative) Metadata() *interop.ContractMD {
3126
return &c.ContractMD
3227
}
@@ -39,37 +34,37 @@ func newNEP17Native(name string, id int32, onManifestConstruction func(m *manife
3934
}
4035
})}
4136

42-
desc := NewDescriptor("symbol", smartcontract.StringType)
43-
md := NewMethodAndPrice(n.Symbol, 0, callflag.NoneFlag)
37+
desc := native.NewDescriptor("symbol", smartcontract.StringType)
38+
md := native.NewMethodAndPrice(n.Symbol, 0, callflag.NoneFlag)
4439
n.AddMethod(md, desc)
4540

46-
desc = NewDescriptor("decimals", smartcontract.IntegerType)
47-
md = NewMethodAndPrice(n.Decimals, 0, callflag.NoneFlag)
41+
desc = native.NewDescriptor("decimals", smartcontract.IntegerType)
42+
md = native.NewMethodAndPrice(n.Decimals, 0, callflag.NoneFlag)
4843
n.AddMethod(md, desc)
4944

50-
desc = NewDescriptor("totalSupply", smartcontract.IntegerType)
51-
md = NewMethodAndPrice(n.TotalSupply, 1<<15, callflag.ReadStates)
45+
desc = native.NewDescriptor("totalSupply", smartcontract.IntegerType)
46+
md = native.NewMethodAndPrice(n.TotalSupply, 1<<15, callflag.ReadStates)
5247
n.AddMethod(md, desc)
5348

54-
desc = NewDescriptor("balanceOf", smartcontract.IntegerType,
49+
desc = native.NewDescriptor("balanceOf", smartcontract.IntegerType,
5550
manifest.NewParameter("account", smartcontract.Hash160Type))
56-
md = NewMethodAndPrice(n.balanceOf, 1<<15, callflag.ReadStates)
51+
md = native.NewMethodAndPrice(n.balanceOf, 1<<15, callflag.ReadStates)
5752
n.AddMethod(md, desc)
5853

5954
transferParams := []manifest.Parameter{
6055
manifest.NewParameter("from", smartcontract.Hash160Type),
6156
manifest.NewParameter("to", smartcontract.Hash160Type),
6257
manifest.NewParameter("amount", smartcontract.IntegerType),
6358
}
64-
desc = NewDescriptor("transfer", smartcontract.BoolType,
59+
desc = native.NewDescriptor("transfer", smartcontract.BoolType,
6560
append(transferParams, manifest.NewParameter("data", smartcontract.AnyType))...,
6661
)
67-
md = NewMethodAndPrice(n.Transfer, 1<<17, callflag.States|callflag.AllowCall|callflag.AllowNotify)
62+
md = native.NewMethodAndPrice(n.Transfer, 1<<17, callflag.States|callflag.AllowCall|callflag.AllowNotify)
6863
md.StorageFee = 50
6964
n.AddMethod(md, desc)
7065

71-
eDesc := NewEventDescriptor("Transfer", transferParams...)
72-
eMD := NewEvent(eDesc)
66+
eDesc := native.NewEventDescriptor("Transfer", transferParams...)
67+
eMD := native.NewEvent(eDesc)
7368
n.AddEvent(eMD)
7469

7570
return n
@@ -88,16 +83,7 @@ func (c *nep17TokenNative) Decimals(_ *interop.Context, _ []stackitem.Item) stac
8883
}
8984

9085
func (c *nep17TokenNative) TotalSupply(ic *interop.Context, _ []stackitem.Item) stackitem.Item {
91-
_, supply := c.getTotalSupply(ic.DAO)
92-
return stackitem.NewBigInteger(supply)
93-
}
94-
95-
func (c *nep17TokenNative) getTotalSupply(d *dao.Simple) (state.StorageItem, *big.Int) {
96-
si := d.GetStorageItem(c.ID, totalSupplyKey)
97-
if si == nil {
98-
si = []byte{}
99-
}
100-
return si, bigint.FromBytes(si)
86+
return stackitem.NewBigInteger(big.NewInt(DefaultBalance * native.GASFactor))
10187
}
10288

10389
func (c *nep17TokenNative) Transfer(ic *interop.Context, args []stackitem.Item) stackitem.Item {
@@ -119,63 +105,3 @@ func (c *nep17TokenNative) Mint(ic *interop.Context, h util.Uint160, amount *big
119105

120106
func (c *nep17TokenNative) Burn(ic *interop.Context, h util.Uint160, amount *big.Int) {
121107
}
122-
123-
func NewDescriptor(name string, ret smartcontract.ParamType, ps ...manifest.Parameter) *manifest.Method {
124-
if len(ps) == 0 {
125-
ps = []manifest.Parameter{}
126-
}
127-
return &manifest.Method{
128-
Name: name,
129-
Parameters: ps,
130-
ReturnType: ret,
131-
}
132-
}
133-
134-
// NewMethodAndPrice builds method with the provided descriptor and ActiveFrom/ActiveTill hardfork
135-
// values consequently specified via activations. [config.HFDefault] specified as ActiveFrom is treated
136-
// as active starting from the genesis block.
137-
func NewMethodAndPrice(f interop.Method, cpuFee int64, flags callflag.CallFlag, activations ...config.Hardfork) *interop.MethodAndPrice {
138-
md := &interop.MethodAndPrice{
139-
HFSpecificMethodAndPrice: interop.HFSpecificMethodAndPrice{
140-
Func: f,
141-
CPUFee: cpuFee,
142-
RequiredFlags: flags,
143-
},
144-
}
145-
if len(activations) > 0 {
146-
if activations[0] != config.HFDefault {
147-
md.ActiveFrom = &activations[0]
148-
}
149-
}
150-
if len(activations) > 1 {
151-
md.ActiveTill = &activations[1]
152-
}
153-
return md
154-
}
155-
156-
func NewEventDescriptor(name string, ps ...manifest.Parameter) *manifest.Event {
157-
if len(ps) == 0 {
158-
ps = []manifest.Parameter{}
159-
}
160-
return &manifest.Event{
161-
Name: name,
162-
Parameters: ps,
163-
}
164-
}
165-
166-
// NewEvent builds event with the provided descriptor and ActiveFrom/ActiveTill hardfork
167-
// values consequently specified via activations.
168-
func NewEvent(desc *manifest.Event, activations ...config.Hardfork) interop.Event {
169-
md := interop.Event{
170-
HFSpecificEvent: interop.HFSpecificEvent{
171-
MD: desc,
172-
},
173-
}
174-
if len(activations) > 0 {
175-
md.ActiveFrom = &activations[0]
176-
}
177-
if len(activations) > 1 {
178-
md.ActiveTill = &activations[1]
179-
}
180-
return md
181-
}

pkg/innerring/internal/metachain/meta/meta.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ func NewMetadata(neo native.INEO) *MetaData {
7575
md = native.NewMethodAndPrice(m.updateContainerList, 1<<15, callflag.WriteStates)
7676
m.AddMethod(md, desc)
7777

78+
desc = native.NewDescriptor("verifyPlacementSignatures", smartcontract.BoolType,
79+
manifest.NewParameter("container", smartcontract.Hash256Type),
80+
manifest.NewParameter("signatures", smartcontract.ArrayType))
81+
md = native.NewMethodAndPrice(m.verifyPlacementSignatures, 1<<15, callflag.ReadOnly)
82+
m.AddMethod(md, desc)
83+
7884
eDesc := native.NewEventDescriptor(putObjectEvent,
7985
manifest.NewParameter("container", smartcontract.Hash256Type),
8086
manifest.NewParameter("object", smartcontract.Hash256Type),

0 commit comments

Comments
 (0)