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-
3025func (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
9085func (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
10389func (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
120106func (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- }
0 commit comments