Commit graph

79 commits

Author SHA1 Message Date
Evgenii Stratonikov
d447064515 util: implement FixedN from string
When working with NEP5 contracts we frequently need
to parse fixed-point decimals with arbitrary precision.
2020-03-10 13:02:14 +03:00
Roman Khimov
823798514a util: rename Int64Value to IntegralValue, add FractionalValue
Makes it's interface more clear and allows to easily access fractional part.
2020-03-04 19:23:23 +03:00
Roman Khimov
e41d434a49 *: move all packages from CityOfZion to nspcc-dev 2020-03-03 17:21:42 +03:00
Evgenii Stratonikov
24bb66e606 util: fix a bug with not copying slice of len=1 in ArrayReverse
ArrayReverse copies it's argument only if it's len is > 1.
It needs to be consistent in all cases.
2020-02-06 12:15:35 +03:00
Evgenii Stratonikov
d07d6f3371 util: refactor tests for ArrayReverse 2020-02-06 12:15:35 +03:00
Evgenii Stratonikov
2f865480d3 util: add YAML marshaler to Fixed8 2020-01-22 14:31:57 +03:00
Roman Khimov
54d888ba70 io: add type-specific read/write methods
This seriously improves the serialization/deserialization performance for
several reasons:
 * no time spent in `binary` reflection
 * no memory allocations being made on every read/write
 * uses fast ReadBytes everywhere it's appropriate

It also makes Fixed8 Serializable just for convenience.
2019-12-12 20:19:50 +03:00
Roman Khimov
5b6c5af704 *: implement EncodeBinary with pointer receivers where appropriate
Everywhere except ParamType (which is just a byte), reduce copying things
around for no real reason.
2019-12-09 18:25:15 +03:00
Evgenii Stratonikov
fccb008594 io: implement ReadBytes() 2019-12-09 15:00:15 +03:00
Roman Khimov
e4d821f32d
Merge pull request #546 from nspcc-dev/write-optimizations
Write optimizations
2019-12-06 19:40:38 +03:00
Roman Khimov
844491d365 *: use more efficient WriteBytes where appropriate
Before this patch on block import we could easily be spending more than 6
seconds out of 30 in Uint256 encoding for UnspentBalance, now it's completely
off the radar.
2019-12-06 18:22:21 +03:00
Evgenii Stratonikov
aa20a95181 util: add Uint256DecodeStringBE() 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
72fe884faa util: add Uint160DecodeStringLE() 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
07e832f046 util: add Uint160DecodeBytesLE() 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
09b295d727 util: add Uint160.Reverse() 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
9e04e61533 util: make Uint160Size public 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
57efad912c util: add LE suffix to Uint160 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
d018dc4e56 util: add missing tests for Uint160 2019-11-25 11:55:26 +03:00
Evgenii Stratonikov
18075bc5c8 util: add missing tests for Fixed8 2019-11-25 11:54:59 +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
Evgenii Stratonikov
61fdd5cde5 util: make Uint256Size public 2019-11-13 17:09:55 +03:00
Vsevolod Brekelov
8ee421db14 fix spelling and godoc comments 2019-10-22 17:56:03 +03:00
Vsevolod Brekelov
59e3bd2fa9 codestyle: fix error string should not be capitalized 2019-10-18 18:34:58 +03:00
Roman Khimov
8537700b7b core: sort hashes and witnesses in VerifyWitnesses()
Fixes failure to verify some multi-witnesses transactions in Testnet chain. C#
code contains similar logic.
2019-10-01 13:41:26 +03:00
Roman Khimov
e299a44983 io: drop Size() method from Serializable and associated
It's no longer needed after the io.GetVarSize() improvement. It's duplicating
a lot of EncodeBinary() logic also.
2019-09-17 13:21:45 +03:00
Roman Khimov
0da9fe6946 io: move size calculator there
It's mostly used for Serializable and in other cases where one needs to
estimate binary-encoded size of the stucture. This also simplifies future
removal of the Size() from Serializable.
2019-09-16 23:39:54 +03:00
Roman Khimov
5bf00db2c9 io: move BinReader/BinWriter there, redo Serializable with it
The logic here is that we'll have all binary encoding/decoding done via our io
package, which simplifies error handling. This functionality doesn't belong to
util, so it's moved.

This also expands BufBinWriter with Reset() method to fit the needs of core
package.
2019-09-16 23:39:51 +03:00
Roman Khimov
031a260cb1 util: add tests for BinaryReader/BinaryWriter
100% coverage.
2019-09-16 23:38:48 +03:00
Roman Khimov
72fc880182 util: remove bogus check from BinWriter.WriteVarUint()
val is uint64, it can't be less than zero by definition.
2019-09-16 23:38:48 +03:00
Roman Khimov
aacf58c9ab util: add 'constructors' for BinReader/BinWriter
And an additional BufBinWriter to ease buffer management.
2019-09-16 23:38:48 +03:00
Roman Khimov
8d9bc83214 util: drop Endpoint structure, fix #321
I think it's useless, buggy and hides parsing errors for no good reason.
2019-09-09 17:54:38 +03:00
Roman Khimov
fabd11699a *: gofmt -s
Appy gofmt for all the source tree.
2019-09-09 12:02:24 +03:00
Roman Khimov
8c448ab890 util: add some tests to make GetVarSize() fully covered 2019-09-07 10:28:00 +03:00
Roman Khimov
6bfcc615b2 *: fix some misspellings
Found by goreport.
2019-09-03 18:20:05 +03:00
Roman Khimov
7b46f9bb86 util: add error check to Read/WriteVarUint
Fixes possibility of bogus reads/writes. Suggested by @im-kulikov.
2019-08-29 13:26:03 +03:00
Roman Khimov
15311f202b util: drop io, reuse its tests for binaryRW 2019-08-28 19:45:17 +03:00
Roman Khimov
07096a551b util: move strange Read2000Uint256Hashes() into storage
It's the only user of it.
2019-08-28 14:38:57 +03:00
Roman Khimov
672668b9fb util: use more consistent and explicit naming for BR/BW 2019-08-28 13:24:06 +03:00
Roman Khimov
6409cc753c util: move binaryReader/Writer from _pkg.dev
These are useful and nice.
2019-08-28 12:44:23 +03:00
Roman Khimov
ec7e17ffa6 pkg: make use of the new crypto/hash package
Simplifies a lot of code and removes some duplication. Unfortunately I had to
move test_util random functions in same commit to avoid cycle
dependencies. One of these random functions was also used in core/transaction
testing, to simplify things I've just dropped it there and used a static
string (which is nice to have for a test anyway).

There is still sha256 left in wallet (but it needs to pass Hash structure into
the signing function).
2019-08-26 13:32:19 +03:00
Roman Khimov
2fd782eee8 util: drop RandUint32()
I don't see anything useful in it, all the current users of it should just use
plain rand.Uint32() not limiting its output in any way.
2019-08-26 13:32:19 +03:00
Roman Khimov
5c5878968b hask: import package from _pkg.dev, make it compile 2019-08-26 13:32:19 +03:00
Roman Khimov
37be2e215c array: add a test for even num of elements
And drop duplicating code from _pkg.dev.
2019-08-26 13:32:19 +03:00
Roman Khimov
0cde8d962d fixed8: switch to more uniform function naming 2019-08-26 13:32:19 +03:00
Roman Khimov
b0af8b306d fixed8: fix Satoshi() and add a test for it 2019-08-26 13:32:19 +03:00
Roman Khimov
20a4ad99b3 fixed8: add some testcases from dev, split Value functions
Add FloatValue() and rename Value() to Int64Value() for consistency.
2019-08-26 13:32:19 +03:00
Roman Khimov
a861f53733 fixed8: simplify arithmetic functions
I'm not sure they're of any use at all.
2019-08-26 13:32:19 +03:00