Commit graph

22 commits

Author SHA1 Message Date
Roman Khimov
1b83dc2476 *: improve for loop syntax
Mostly it's about Go 1.22+ syntax with ranging over integers, but it also
prefers ranging over slices where possible (it makes code a little better to
read).

Notice that we have a number of dangerous loops where slices are mutated
during loop execution, many of these can't be converted since we need proper
length evalutation at every iteration.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-30 21:45:18 +03:00
Roman Khimov
b4e4567c2b *: don't use CompareTo name for three-way comparison functions
"Compare" is almost a standard one now, although math/big uses Cmp for historic
reasons (keys.PublicKey does so too). This also fixes Fixed8 since int64 to int
conversion is lossy.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 12:29:44 +03:00
Evgeniy Stratonikov
8c31831626 util: reduce allocations in util.Uint256DecodeStringLE
It is used a lot in clients (including our benchmark).
`Uint160` is already optimized.

```
name                     old time/op    new time/op    delta
Uint256DecodeStringLE-8     150ns ±15%     112ns ± 3%  -25.23%  (p=0.000 n=10+10)

name                     old alloc/op   new alloc/op   delta
Uint256DecodeStringLE-8     96.0B ± 0%     64.0B ± 0%  -33.33%  (p=0.000 n=10+10)

name                     old allocs/op  new allocs/op  delta
Uint256DecodeStringLE-8      2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.000 n=10+10)
```

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-17 16:53:39 +03:00
Roman Khimov
aab18c3083 stackitem: introduce Convertible interface
We have a lot of native contract types that are converted to stack items
before serialization, then deserialized as stack items and converted back to
regular structures. stackitem.Convertible allows to remove a lot of repetitive
io.Serializable code.

This also introduces to/from converter in testserdes which unfortunately
required to change util tests to avoid circular references.
2021-07-19 15:42:42 +03:00
Evgenii Stratonikov
7d91a3a89e pkg: move internal/ package to the root directory
This way we can use it in scripts and cli.
2020-11-24 16:39:56 +03:00
Evgenii Stratonikov
9abda40171 testserdes: implement helpers for encode/decode routines
Frequently one needs to check if struct serializes/deserializes
properly. This commit implements helpers for such cases including:
1. JSON
2. io.Serializable interface
2020-03-27 10:27:46 +03:00
Roman Khimov
e41d434a49 *: move all packages from CityOfZion to nspcc-dev 2020-03-03 17:21:42 +03:00
Evgenii Stratonikov
aa20a95181 util: add Uint256DecodeStringBE() 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
7179e4ba9f util: add LE suffix to Uint256 methods 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
ab922c1810 util: add missing tests for Uint256 2019-11-25 11:55:26 +03:00
Evgenii Stratonikov
116d4c656e util: make tests use require 2019-11-25 11:53:49 +03:00
Evgenii Stratonikov
2be18f91df util: implement io.Serializable for Uint256 2019-11-14 14:20:38 +03:00
Vsevolod Brekelov
8ee421db14 fix spelling and godoc comments 2019-10-22 17:56:03 +03:00
Roman Khimov
d5d570f793 uint256: add Reverse(), change String() to be BE
This one makes a little more obvious that we're operating with LE
representations mostly. Refs. #307. See #314 also.
2019-08-26 13:32:19 +03:00
Evgeniy Kulikov
6ccb518ab0 Optimizations + some improvements (#105)
* Optimizations + some improvements

- optimized pkg/core/storage.HeaderHashes
- optimized pkg/rpc.performRequest (used json.Encoder)
- fixes for pkg/util.ReadVarUint and pkg/util.WriteVarUint
- optimized and fix fixed8 (Fixed8DecodeString / MarshalJSON) + tests
- optimized and fix uint160 (Bytes / Uint160DecodeString / Equal / MarshalJSON) + tests
- optimized and fix uint256 (Bytes / Equal / MarshalJSON) + tests
- preallocate for pkg/vm.buildStackOutput
- add go.mod / go.sum

* update version
2018-11-26 16:56:45 +01:00
1d9045877c Add JSON unmarshallers for numeric types from util (#83)
Uint160, Uint256, Fixed8 now have UnmarshalJSON method.
2018-05-09 07:20:16 +02:00
Anthony De Meulemeester
1a1a19da7d
Smartcontract (#39)
* deleted transfer_output added asset type and transaction result to core

* removed writing 0x00 when buffer length is 0

* Refactored emit into VM package + moved tx to own package.

* implemented transaction along with claimTransaction.

* refactored naming of transaction + added decode address for uint160 types

* removed unnecessary folder and files.

* transaction/smartcontract logic

* bumped version 0.24.0
2018-03-04 14:56:49 +01:00
Anthony De Meulemeester
f3f6662fc9
Base wallet implementation (#35)
* Initial draft of the neo-go wallet

* Cleanup + more test for util package

* integrated wallet into neo-cli partially

* base wallet implementation + smartcontract code.
2018-03-02 16:24:09 +01:00
Anthony De Meulemeester
b257a06f3e
Compiler update (#21)
* added seperate folders for cmd packages.

* Fix netmodes in test + reverse bigint bytes

* glide get deps

* add, sub, mul, div

* booleans

* strings

* binary expressions

* if statements

* function calls

* composite literals (slice, array)

* Added lots of test cases and update readme.
2018-02-15 16:35:49 +01:00
Anthony De Meulemeester
628656483a
bug fixes (TCP + uint256) and started core part (#14)
* Fixed TCP read + Uint256 reversed array + started on some core pieces

* Disabled some debug output + muted test

* 0.5.0
2018-02-04 20:54:51 +01:00
anthdm
e9f9354b86 added core block type 2018-01-30 11:56:36 +01:00
anthdm
68088d816c checked missing files for inventory. 2018-01-28 08:05:35 +01:00