forked from TrueCloudLab/neoneo-go
util: add LE suffix to Uint256 methods
This commit is contained in:
parent
57efad912c
commit
7179e4ba9f
40 changed files with 143 additions and 138 deletions
|
@ -423,7 +423,7 @@ func invokeInternal(ctx *cli.Context, withMethod bool, signAndPush bool) error {
|
|||
if err != nil {
|
||||
return cli.NewExitError(fmt.Errorf("failed to push invocation tx: %v", err), 1)
|
||||
}
|
||||
fmt.Printf("Sent invocation transaction %s\n", txHash.ReverseString())
|
||||
fmt.Printf("Sent invocation transaction %s\n", txHash.StringLE())
|
||||
} else {
|
||||
b, err := json.MarshalIndent(resp.Result, "", " ")
|
||||
if err != nil {
|
||||
|
@ -585,6 +585,6 @@ func contractDeploy(ctx *cli.Context) error {
|
|||
if err != nil {
|
||||
return cli.NewExitError(fmt.Errorf("failed to push invocation tx: %v", err), 1)
|
||||
}
|
||||
fmt.Printf("Sent deployment transaction %s for contract %s\n", txHash.ReverseString(), hash.Hash160(avm).StringLE())
|
||||
fmt.Printf("Sent deployment transaction %s for contract %s\n", txHash.StringLE(), hash.Hash160(avm).StringLE())
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ func putAssetStateIntoStore(s storage.Store, as *AssetState) error {
|
|||
if buf.Err != nil {
|
||||
return buf.Err
|
||||
}
|
||||
key := storage.AppendPrefix(storage.STAsset, as.ID.Bytes())
|
||||
key := storage.AppendPrefix(storage.STAsset, as.ID.BytesBE())
|
||||
return s.Put(key, buf.Bytes())
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ func (b *Block) Verify() error {
|
|||
// If the first TX is a minerTX then all others cant.
|
||||
for _, tx := range b.Transactions[1:] {
|
||||
if tx.Type == transaction.MinerType {
|
||||
return fmt.Errorf("miner transaction %s is not the first one", tx.Hash().ReverseString())
|
||||
return fmt.Errorf("miner transaction %s is not the first one", tx.Hash().StringLE())
|
||||
}
|
||||
}
|
||||
merkle, err := merkleTreeFromTransactions(b.Transactions)
|
||||
|
|
|
@ -31,9 +31,9 @@ func TestDecodeBlock1(t *testing.T) {
|
|||
|
||||
assert.Equal(t, uint32(data["index"].(float64)), block.Index)
|
||||
assert.Equal(t, uint32(data["version"].(float64)), block.Version)
|
||||
assert.Equal(t, data["hash"].(string), block.Hash().ReverseString())
|
||||
assert.Equal(t, data["previousblockhash"].(string), block.PrevHash.ReverseString())
|
||||
assert.Equal(t, data["merkleroot"].(string), block.MerkleRoot.ReverseString())
|
||||
assert.Equal(t, data["hash"].(string), block.Hash().StringLE())
|
||||
assert.Equal(t, data["previousblockhash"].(string), block.PrevHash.StringLE())
|
||||
assert.Equal(t, data["merkleroot"].(string), block.MerkleRoot.StringLE())
|
||||
assert.Equal(t, data["nextconsensus"].(string), crypto.AddressFromUint160(block.NextConsensus))
|
||||
|
||||
script := data["script"].(map[string]interface{})
|
||||
|
@ -169,13 +169,13 @@ func TestBinBlockDecodeEncode(t *testing.T) {
|
|||
for _, tx := range b.Transactions {
|
||||
switch tx.Type {
|
||||
case transaction.ContractType:
|
||||
hashes = append(hashes, tx.Hash().ReverseString())
|
||||
hashes = append(hashes, tx.Hash().StringLE())
|
||||
case transaction.MinerType:
|
||||
hashes = append(hashes, tx.Hash().ReverseString())
|
||||
hashes = append(hashes, tx.Hash().StringLE())
|
||||
case transaction.ClaimType:
|
||||
hashes = append(hashes, tx.Hash().ReverseString())
|
||||
hashes = append(hashes, tx.Hash().StringLE())
|
||||
case transaction.InvocationType:
|
||||
hashes = append(hashes, tx.Hash().ReverseString())
|
||||
hashes = append(hashes, tx.Hash().StringLE())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -253,7 +253,7 @@ func TestBlockSizeCalculation(t *testing.T) {
|
|||
|
||||
for i, tx := range b.Transactions {
|
||||
txID := tx.Hash()
|
||||
assert.Equal(t, expected[i].ID, txID.ReverseString())
|
||||
assert.Equal(t, expected[i].ID, txID.StringLE())
|
||||
|
||||
assert.Equal(t, expected[i].Size, io.GetVarSize(tx))
|
||||
assert.Equal(t, expected[i].Type, tx.Type.String())
|
||||
|
@ -268,8 +268,8 @@ func TestBlockSizeCalculation(t *testing.T) {
|
|||
|
||||
// Block specific tests
|
||||
assert.Equal(t, 0, int(b.Version))
|
||||
assert.Equal(t, "f4889276813c65c059cb54612e9e51b1b8fd91ee799e03b638bfade812df33ba", b.PrevHash.ReverseString())
|
||||
assert.Equal(t, "ef7241eb3dc1df2c95dc9bed9dea2814b62e61286c22d77e07847a9b109224a2", b.MerkleRoot.ReverseString())
|
||||
assert.Equal(t, "f4889276813c65c059cb54612e9e51b1b8fd91ee799e03b638bfade812df33ba", b.PrevHash.StringLE())
|
||||
assert.Equal(t, "ef7241eb3dc1df2c95dc9bed9dea2814b62e61286c22d77e07847a9b109224a2", b.MerkleRoot.StringLE())
|
||||
assert.Equal(t, 1527894405, int(b.Timestamp))
|
||||
assert.Equal(t, 2340363, int(b.Index))
|
||||
|
||||
|
@ -278,7 +278,7 @@ func TestBlockSizeCalculation(t *testing.T) {
|
|||
|
||||
assert.Equal(t, "4012afae6df64195041e4764b57caa9e27fc2cfc596833163904136ec95816d104b44b3737d0e9f6b1b4445cd3b6a5cc80f6b0935675bc44dba44415eb309832b3404dc95bcf85e4635556a1d618e4ce947b26972992ed74788df5f9501b850ac0b40b7112d1ff30e4ade00369e16f0d13932d1ba76725e7682db072f8e2cd7752b840d12bb7dd45dd3b0e2098db5c67b6de55b7c40164937491fcaca1239b25860251224ead23ab232add78ccccd347239eae50ffc98f50b2a84c60ec5c3d284647a7406fabf6ca241b759af6b71080c0dfad7395632e989226a7e52f8cd2c133aeb2226e6e1aea47666fd81f578405a9f9bbd9d0bc523c3a44d7a5099ddc649feabe5f406188b8ee478731a89beeb76fdbd108eb0071b8f2b8678f40c5a1f387a491314336783255dee8cc5af4bf914dfeaacecc318fc13e02262658e39e8ce0631941b1", hex.EncodeToString(b.Script.InvocationScript))
|
||||
assert.Equal(t, "552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae", hex.EncodeToString(b.Script.VerificationScript))
|
||||
assert.Equal(t, "0006d3ff96e269f599eb1b5c5a527c218439e498dcc65b63794591bbcdc0516b", b.Hash().ReverseString())
|
||||
assert.Equal(t, "0006d3ff96e269f599eb1b5c5a527c218439e498dcc65b63794591bbcdc0516b", b.Hash().StringLE())
|
||||
|
||||
buf := io.NewBufBinWriter()
|
||||
|
||||
|
|
|
@ -238,13 +238,13 @@ func (bc *Blockchain) AddBlock(block *Block) error {
|
|||
err = bc.VerifyBlock(block)
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("block %s is invalid: %s", block.Hash().ReverseString(), err)
|
||||
return fmt.Errorf("block %s is invalid: %s", block.Hash().StringLE(), err)
|
||||
}
|
||||
if bc.config.VerifyTransactions {
|
||||
for _, tx := range block.Transactions {
|
||||
err := bc.VerifyTx(tx, block)
|
||||
if err != nil {
|
||||
return fmt.Errorf("transaction %s failed to verify: %s", tx.Hash().ReverseString(), err)
|
||||
return fmt.Errorf("transaction %s failed to verify: %s", tx.Hash().StringLE(), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -327,7 +327,7 @@ func (bc *Blockchain) processHeader(h *Header, batch storage.Batch, headerList *
|
|||
return buf.Err
|
||||
}
|
||||
|
||||
key := storage.AppendPrefix(storage.DataBlock, h.Hash().BytesReverse())
|
||||
key := storage.AppendPrefix(storage.DataBlock, h.Hash().BytesLE())
|
||||
batch.Put(key, buf.Bytes())
|
||||
batch.Put(storage.SYSCurrentHeader.Bytes(), hashAndIndexToBytes(h.Hash(), h.Index))
|
||||
|
||||
|
@ -490,7 +490,7 @@ func (bc *Blockchain) storeBlock(block *Block) error {
|
|||
case *transaction.InvocationTX:
|
||||
systemInterop := newInteropContext(trigger.Application, bc, chainState.store, block, tx)
|
||||
v := bc.spawnVMWithInterops(systemInterop)
|
||||
v.SetCheckedHash(tx.VerificationHash().Bytes())
|
||||
v.SetCheckedHash(tx.VerificationHash().BytesBE())
|
||||
v.LoadScript(t.Script)
|
||||
err := v.Run()
|
||||
if !v.HasFailed() {
|
||||
|
@ -524,7 +524,7 @@ func (bc *Blockchain) storeBlock(block *Block) error {
|
|||
}
|
||||
} else {
|
||||
log.WithFields(log.Fields{
|
||||
"tx": tx.Hash().ReverseString(),
|
||||
"tx": tx.Hash().StringLE(),
|
||||
"block": block.Index,
|
||||
"err": err,
|
||||
}).Warn("contract invocation failed")
|
||||
|
@ -700,7 +700,7 @@ func (bc *Blockchain) GetTransaction(hash util.Uint256) (*transaction.Transactio
|
|||
// getTransactionFromStore returns Transaction and its height by the given hash
|
||||
// if it exists in the store.
|
||||
func getTransactionFromStore(s storage.Store, hash util.Uint256) (*transaction.Transaction, uint32, error) {
|
||||
key := storage.AppendPrefix(storage.DataTransaction, hash.BytesReverse())
|
||||
key := storage.AppendPrefix(storage.DataTransaction, hash.BytesLE())
|
||||
b, err := s.Get(key)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
|
@ -772,7 +772,7 @@ func (bc *Blockchain) GetBlock(hash util.Uint256) (*Block, error) {
|
|||
|
||||
// getBlockFromStore returns Block by the given hash if it exists in the store.
|
||||
func getBlockFromStore(s storage.Store, hash util.Uint256) (*Block, error) {
|
||||
key := storage.AppendPrefix(storage.DataBlock, hash.BytesReverse())
|
||||
key := storage.AppendPrefix(storage.DataBlock, hash.BytesLE())
|
||||
b, err := s.Get(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -808,7 +808,7 @@ func (bc *Blockchain) HasTransaction(hash util.Uint256) bool {
|
|||
// checkTransactionInStore returns true if the given store contains the given
|
||||
// Transaction hash.
|
||||
func checkTransactionInStore(s storage.Store, hash util.Uint256) bool {
|
||||
key := storage.AppendPrefix(storage.DataTransaction, hash.BytesReverse())
|
||||
key := storage.AppendPrefix(storage.DataTransaction, hash.BytesLE())
|
||||
if _, err := s.Get(key); err == nil {
|
||||
return true
|
||||
}
|
||||
|
@ -870,7 +870,7 @@ func (bc *Blockchain) GetAssetState(assetID util.Uint256) *AssetState {
|
|||
// getAssetStateFromStore returns given asset state as recorded in the given
|
||||
// store.
|
||||
func getAssetStateFromStore(s storage.Store, assetID util.Uint256) *AssetState {
|
||||
key := storage.AppendPrefix(storage.STAsset, assetID.Bytes())
|
||||
key := storage.AppendPrefix(storage.STAsset, assetID.BytesBE())
|
||||
asEncoded, err := s.Get(key)
|
||||
if err != nil {
|
||||
return nil
|
||||
|
@ -1059,16 +1059,16 @@ func (bc *Blockchain) verifyOutputs(t *transaction.Transaction) error {
|
|||
for assetID, outputs := range t.GroupOutputByAssetID() {
|
||||
assetState := bc.GetAssetState(assetID)
|
||||
if assetState == nil {
|
||||
return fmt.Errorf("no asset state for %s", assetID.ReverseString())
|
||||
return fmt.Errorf("no asset state for %s", assetID.StringLE())
|
||||
}
|
||||
|
||||
if assetState.Expiration < bc.blockHeight+1 && assetState.AssetType != transaction.GoverningToken && assetState.AssetType != transaction.UtilityToken {
|
||||
return fmt.Errorf("asset %s expired", assetID.ReverseString())
|
||||
return fmt.Errorf("asset %s expired", assetID.StringLE())
|
||||
}
|
||||
|
||||
for _, out := range outputs {
|
||||
if int64(out.Amount)%int64(math.Pow10(8-int(assetState.Precision))) != 0 {
|
||||
return fmt.Errorf("output is not compliant with %s asset precision", assetID.ReverseString())
|
||||
return fmt.Errorf("output is not compliant with %s asset precision", assetID.StringLE())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1442,7 +1442,7 @@ func (bc *Blockchain) verifyHashAgainstScript(hash util.Uint160, witness *transa
|
|||
}
|
||||
|
||||
vm := bc.spawnVMWithInterops(interopCtx)
|
||||
vm.SetCheckedHash(checkedHash.Bytes())
|
||||
vm.SetCheckedHash(checkedHash.BytesBE())
|
||||
vm.LoadScript(verification)
|
||||
vm.LoadScript(witness.InvocationScript)
|
||||
err := vm.Run()
|
||||
|
@ -1509,7 +1509,7 @@ func (bc *Blockchain) verifyBlockWitnesses(block *Block, prevHeader *Header) err
|
|||
|
||||
func hashAndIndexToBytes(h util.Uint256, index uint32) []byte {
|
||||
buf := io.NewBufBinWriter()
|
||||
buf.WriteBytes(h.BytesReverse())
|
||||
buf.WriteBytes(h.BytesLE())
|
||||
buf.WriteLE(index)
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ func (state *BlockChainState) commit() error {
|
|||
// storeAsBlock stores the given block as DataBlock.
|
||||
func (state *BlockChainState) storeAsBlock(block *Block, sysFee uint32) error {
|
||||
var (
|
||||
key = storage.AppendPrefix(storage.DataBlock, block.Hash().BytesReverse())
|
||||
key = storage.AppendPrefix(storage.DataBlock, block.Hash().BytesLE())
|
||||
buf = io.NewBufBinWriter()
|
||||
)
|
||||
// sysFee needs to be handled somehow
|
||||
|
@ -79,14 +79,14 @@ func (state *BlockChainState) storeAsBlock(block *Block, sysFee uint32) error {
|
|||
// storeAsCurrentBlock stores the given block witch prefix SYSCurrentBlock.
|
||||
func (state *BlockChainState) storeAsCurrentBlock(block *Block) error {
|
||||
buf := io.NewBufBinWriter()
|
||||
buf.WriteBytes(block.Hash().BytesReverse())
|
||||
buf.WriteBytes(block.Hash().BytesLE())
|
||||
buf.WriteLE(block.Index)
|
||||
return state.store.Put(storage.SYSCurrentBlock.Bytes(), buf.Bytes())
|
||||
}
|
||||
|
||||
// storeAsTransaction stores the given TX as DataTransaction.
|
||||
func (state *BlockChainState) storeAsTransaction(tx *transaction.Transaction, index uint32) error {
|
||||
key := storage.AppendPrefix(storage.DataTransaction, tx.Hash().BytesReverse())
|
||||
key := storage.AppendPrefix(storage.DataTransaction, tx.Hash().BytesLE())
|
||||
buf := io.NewBufBinWriter()
|
||||
buf.WriteLE(index)
|
||||
tx.EncodeBinary(buf.BinWriter)
|
||||
|
|
|
@ -55,7 +55,7 @@ func TestAddBlock(t *testing.T) {
|
|||
require.NoError(t, bc.persist())
|
||||
|
||||
for _, block := range blocks {
|
||||
key := storage.AppendPrefix(storage.DataBlock, block.Hash().BytesReverse())
|
||||
key := storage.AppendPrefix(storage.DataBlock, block.Hash().BytesLE())
|
||||
if _, err := bc.store.Get(key); err != nil {
|
||||
t.Fatalf("block %s not persisted", block.Hash())
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ func (ic *interopContext) headerGetMerkleRoot(v *vm.VM) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.Estack().PushVal(header.MerkleRoot.BytesReverse())
|
||||
v.Estack().PushVal(header.MerkleRoot.BytesLE())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,7 @@ func (ic *interopContext) inputGetHash(v *vm.VM) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.Estack().PushVal(input.PrevHash.Bytes())
|
||||
v.Estack().PushVal(input.PrevHash.BytesBE())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -261,7 +261,7 @@ func (ic *interopContext) outputGetAssetID(v *vm.VM) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.Estack().PushVal(output.AssetID.Bytes())
|
||||
v.Estack().PushVal(output.AssetID.BytesBE())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -325,7 +325,7 @@ func (ic *interopContext) bcGetAccount(v *vm.VM) error {
|
|||
// bcGetAsset returns an asset.
|
||||
func (ic *interopContext) bcGetAsset(v *vm.VM) error {
|
||||
asbytes := v.Estack().Pop().Bytes()
|
||||
ashash, err := util.Uint256DecodeBytes(asbytes)
|
||||
ashash, err := util.Uint256DecodeBytesBE(asbytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ func (ic *interopContext) accountGetBalance(v *vm.VM) error {
|
|||
return fmt.Errorf("%T is not an account state", acc)
|
||||
}
|
||||
asbytes := v.Estack().Pop().Bytes()
|
||||
ashash, err := util.Uint256DecodeBytes(asbytes)
|
||||
ashash, err := util.Uint256DecodeBytesBE(asbytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -657,7 +657,7 @@ func (ic *interopContext) assetGetAssetID(v *vm.VM) error {
|
|||
if !ok {
|
||||
return fmt.Errorf("%T is not an asset state", as)
|
||||
}
|
||||
v.Estack().PushVal(as.ID.Bytes())
|
||||
v.Estack().PushVal(as.ID.BytesBE())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ func TestHeaderGetMerkleRoot(t *testing.T) {
|
|||
err := context.headerGetMerkleRoot(v)
|
||||
require.NoError(t, err)
|
||||
value := v.Estack().Pop().Value()
|
||||
require.Equal(t, block.MerkleRoot.BytesReverse(), value)
|
||||
require.Equal(t, block.MerkleRoot.BytesLE(), value)
|
||||
}
|
||||
|
||||
func TestHeaderGetNextConsensus(t *testing.T) {
|
||||
|
@ -129,7 +129,7 @@ func TestInputGetHash(t *testing.T) {
|
|||
err := context.inputGetHash(v)
|
||||
require.NoError(t, err)
|
||||
hash := v.Estack().Pop().Value()
|
||||
require.Equal(t, tx.Inputs[0].PrevHash.Bytes(), hash)
|
||||
require.Equal(t, tx.Inputs[0].PrevHash.BytesBE(), hash)
|
||||
}
|
||||
|
||||
func TestInputGetIndex(t *testing.T) {
|
||||
|
@ -158,7 +158,7 @@ func TestOutputGetAssetID(t *testing.T) {
|
|||
err := context.outputGetAssetID(v)
|
||||
require.NoError(t, err)
|
||||
assetID := v.Estack().Pop().Value()
|
||||
require.Equal(t, tx.Outputs[0].AssetID.Bytes(), assetID)
|
||||
require.Equal(t, tx.Outputs[0].AssetID.BytesBE(), assetID)
|
||||
}
|
||||
|
||||
func TestOutputGetScriptHash(t *testing.T) {
|
||||
|
@ -268,7 +268,7 @@ func TestAssetGetAssetID(t *testing.T) {
|
|||
err := context.assetGetAssetID(v)
|
||||
require.NoError(t, err)
|
||||
assetID := v.Estack().Pop().Value()
|
||||
require.Equal(t, assetState.ID.Bytes(), assetID)
|
||||
require.Equal(t, assetState.ID.BytesBE(), assetID)
|
||||
}
|
||||
|
||||
func TestAssetGetAssetType(t *testing.T) {
|
||||
|
|
|
@ -40,7 +40,7 @@ func getBlockHashFromElement(bc Blockchainer, element *vm.Element) (util.Uint256
|
|||
}
|
||||
hash = bc.GetHeaderHash(int(hashint))
|
||||
} else {
|
||||
return util.Uint256DecodeReverseBytes(hashbytes)
|
||||
return util.Uint256DecodeBytesLE(hashbytes)
|
||||
}
|
||||
return hash, nil
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ func (ic *interopContext) bcGetHeight(v *vm.VM) error {
|
|||
// returns transaction and its height if it's present in the blockchain.
|
||||
func getTransactionAndHeight(bc Blockchainer, v *vm.VM) (*transaction.Transaction, uint32, error) {
|
||||
hashbytes := v.Estack().Pop().Bytes()
|
||||
hash, err := util.Uint256DecodeReverseBytes(hashbytes)
|
||||
hash, err := util.Uint256DecodeBytesLE(hashbytes)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ func (ic *interopContext) headerGetHash(v *vm.VM) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.Estack().PushVal(header.Hash().BytesReverse())
|
||||
v.Estack().PushVal(header.Hash().BytesLE())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -170,7 +170,7 @@ func (ic *interopContext) headerGetPrevHash(v *vm.VM) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.Estack().PushVal(header.PrevHash.BytesReverse())
|
||||
v.Estack().PushVal(header.PrevHash.BytesLE())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -237,7 +237,7 @@ func (ic *interopContext) txGetHash(v *vm.VM) error {
|
|||
if !ok {
|
||||
return errors.New("value is not a transaction")
|
||||
}
|
||||
v.Estack().PushVal(tx.Hash().BytesReverse())
|
||||
v.Estack().PushVal(tx.Hash().BytesLE())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ func putAppExecResultIntoStore(s storage.Store, aer *AppExecResult) error {
|
|||
if buf.Err != nil {
|
||||
return buf.Err
|
||||
}
|
||||
key := storage.AppendPrefix(storage.STNotification, aer.TxHash.Bytes())
|
||||
key := storage.AppendPrefix(storage.STNotification, aer.TxHash.BytesBE())
|
||||
return s.Put(key, buf.Bytes())
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ func putAppExecResultIntoStore(s storage.Store, aer *AppExecResult) error {
|
|||
// given store.
|
||||
func getAppExecResultFromStore(s storage.Store, hash util.Uint256) (*AppExecResult, error) {
|
||||
aer := &AppExecResult{}
|
||||
key := storage.AppendPrefix(storage.STNotification, hash.Bytes())
|
||||
key := storage.AppendPrefix(storage.STNotification, hash.BytesBE())
|
||||
if b, err := s.Get(key); err == nil {
|
||||
r := io.NewBinReaderFromBuf(b)
|
||||
aer.DecodeBinary(r)
|
||||
|
|
|
@ -18,7 +18,7 @@ func (s SpentCoins) getAndUpdate(store storage.Store, hash util.Uint256) (*Spent
|
|||
}
|
||||
|
||||
spent := &SpentCoinState{}
|
||||
key := storage.AppendPrefix(storage.STSpentCoin, hash.BytesReverse())
|
||||
key := storage.AppendPrefix(storage.STSpentCoin, hash.BytesLE())
|
||||
if b, err := store.Get(key); err == nil {
|
||||
r := io.NewBinReaderFromBuf(b)
|
||||
spent.DecodeBinary(r)
|
||||
|
@ -42,7 +42,7 @@ func putSpentCoinStateIntoStore(store storage.Store, hash util.Uint256, scs *Spe
|
|||
if buf.Err != nil {
|
||||
return buf.Err
|
||||
}
|
||||
key := storage.AppendPrefix(storage.STSpentCoin, hash.BytesReverse())
|
||||
key := storage.AppendPrefix(storage.STSpentCoin, hash.BytesLE())
|
||||
return store.Put(key, buf.Bytes())
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ func CurrentHeaderHeight(s Store) (i uint32, h util.Uint256, err error) {
|
|||
return
|
||||
}
|
||||
i = binary.LittleEndian.Uint32(b[32:36])
|
||||
h, err = util.Uint256DecodeReverseBytes(b[:32])
|
||||
h, err = util.Uint256DecodeBytesLE(b[:32])
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -21,12 +21,12 @@ func TestEncodeDecodeContract(t *testing.T) {
|
|||
|
||||
input := tx.Inputs[0]
|
||||
|
||||
assert.Equal(t, "eec17cc828d6ede932b57e4eaf79c2591151096a7825435cd67f498f9fa98d88", input.PrevHash.ReverseString())
|
||||
assert.Equal(t, "eec17cc828d6ede932b57e4eaf79c2591151096a7825435cd67f498f9fa98d88", input.PrevHash.StringLE())
|
||||
assert.Equal(t, 0, int(input.PrevIndex))
|
||||
assert.Equal(t, int64(706), tx.Outputs[0].Amount.Int64Value())
|
||||
assert.Equal(t, "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", tx.Outputs[0].AssetID.ReverseString())
|
||||
assert.Equal(t, "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", tx.Outputs[0].AssetID.StringLE())
|
||||
assert.Equal(t, "a8666b4830229d6a1a9b80f6088059191c122d2b", tx.Outputs[0].ScriptHash.String())
|
||||
assert.Equal(t, "bdf6cc3b9af12a7565bda80933a75ee8cef1bc771d0d58effc08e4c8b436da79", tx.Hash().ReverseString())
|
||||
assert.Equal(t, "bdf6cc3b9af12a7565bda80933a75ee8cef1bc771d0d58effc08e4c8b436da79", tx.Hash().StringLE())
|
||||
|
||||
// Encode
|
||||
buf := io.NewBufBinWriter()
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
func TestEncodeDecodeEnrollment(t *testing.T) {
|
||||
rawtx := "200002ff8ac54687f36bbc31a91b730cc385da8af0b581f2d59d82b5cfef824fd271f60001d3d3b7028d61fea3b7803fda3d7f0a1f7262d38e5e1c8987b0313e0a94574151000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c60005441d11600000050ac4949596f5b62fef7be4d1c3e494e6048ed4a01414079d78189d591097b17657a62240c93595e8233dc81157ea2cd477813f09a11fd72845e6bd97c5a3dda125985ea3d5feca387e9933649a9a671a69ab3f6301df6232102ff8ac54687f36bbc31a91b730cc385da8af0b581f2d59d82b5cfef824fd271f6ac"
|
||||
tx := decodeTransaction(rawtx, t)
|
||||
assert.Equal(t, "988832f693785dcbcb8d5a0e9d5d22002adcbfb1eb6bbeebf8c494fff580e147", tx.Hash().ReverseString())
|
||||
assert.Equal(t, "988832f693785dcbcb8d5a0e9d5d22002adcbfb1eb6bbeebf8c494fff580e147", tx.Hash().StringLE())
|
||||
assert.Equal(t, EnrollmentType, tx.Type)
|
||||
assert.IsType(t, tx.Data, &EnrollmentTX{})
|
||||
assert.Equal(t, 0, int(tx.Version))
|
||||
|
|
|
@ -18,7 +18,7 @@ func TestEncodeDecodeMiner(t *testing.T) {
|
|||
m := tx.Data.(*MinerTX)
|
||||
assert.Equal(t, uint32(571397116), m.Nonce)
|
||||
|
||||
assert.Equal(t, "a1f219dc6be4c35eca172e65e02d4591045220221b1543f1a4b67b9e9442c264", tx.Hash().ReverseString())
|
||||
assert.Equal(t, "a1f219dc6be4c35eca172e65e02d4591045220221b1543f1a4b67b9e9442c264", tx.Hash().StringLE())
|
||||
|
||||
// Encode
|
||||
buf := io.NewBufBinWriter()
|
||||
|
|
|
@ -60,7 +60,7 @@ func TestDecodeRegisterTXFromRawString(t *testing.T) {
|
|||
assert.Equal(t, uint8(0), txData.Precision)
|
||||
assert.Equal(t, &keys.PublicKey{}, txData.Owner)
|
||||
assert.Equal(t, "Abf2qMs1pzQb8kYk9RuxtUb9jtRKJVuBJt", crypto.AddressFromUint160(txData.Admin))
|
||||
assert.Equal(t, "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", tx.Hash().ReverseString())
|
||||
assert.Equal(t, "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", tx.Hash().StringLE())
|
||||
|
||||
buf := io.NewBufBinWriter()
|
||||
tx.EncodeBinary(buf.BinWriter)
|
||||
|
|
|
@ -14,11 +14,11 @@ func TestEncodeDecodeState(t *testing.T) {
|
|||
tx := decodeTransaction(rawtx, t)
|
||||
assert.Equal(t, StateType, tx.Type)
|
||||
assert.IsType(t, tx.Data, &StateTX{})
|
||||
assert.Equal(t, "8abf5ebdb9a8223b12109513647f45bd3c0a6cf1a6346d56684cff71ba308724", tx.Hash().ReverseString())
|
||||
assert.Equal(t, "8abf5ebdb9a8223b12109513647f45bd3c0a6cf1a6346d56684cff71ba308724", tx.Hash().StringLE())
|
||||
|
||||
assert.Equal(t, 1, len(tx.Inputs))
|
||||
input := tx.Inputs[0]
|
||||
assert.Equal(t, "a192cbabc6d613ecfcce43fd09e9197556ca5cf7d4bd1f6c65726ea9f08441cb", input.PrevHash.ReverseString())
|
||||
assert.Equal(t, "a192cbabc6d613ecfcce43fd09e9197556ca5cf7d4bd1f6c65726ea9f08441cb", input.PrevHash.StringLE())
|
||||
assert.Equal(t, uint16(0), input.PrevIndex)
|
||||
|
||||
s := tx.Data.(*StateTX)
|
||||
|
|
|
@ -53,7 +53,7 @@ func TestDecodeEncodeClaimTX(t *testing.T) {
|
|||
assert.Equal(t, 1, len(tx.Outputs))
|
||||
address := crypto.AddressFromUint160(tx.Outputs[0].ScriptHash)
|
||||
assert.Equal(t, "AQJseD8iBmCD4sgfHRhMahmoi9zvopG6yz", address)
|
||||
assert.Equal(t, "602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7", tx.Outputs[0].AssetID.ReverseString())
|
||||
assert.Equal(t, "602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7", tx.Outputs[0].AssetID.StringLE())
|
||||
assert.Equal(t, tx.Outputs[0].Amount.String(), "0.06247739")
|
||||
invoc := "40456349cec43053009accdb7781b0799c6b591c812768804ab0a0b56b5eae7a97694227fcd33e70899c075848b2cee8fae733faac6865b484d3f7df8949e2aadb"
|
||||
verif := "2103945fae1ed3c31d778f149192b76734fcc951b400ba3598faa81ff92ebe477eacac"
|
||||
|
@ -67,7 +67,7 @@ func TestDecodeEncodeClaimTX(t *testing.T) {
|
|||
assert.Equal(t, rawClaimTX, hex.EncodeToString(buf.Bytes()))
|
||||
|
||||
hash := "2c6a45547b3898318e400e541628990a07acb00f3b9a15a8e966ae49525304da"
|
||||
assert.Equal(t, hash, tx.hash.ReverseString())
|
||||
assert.Equal(t, hash, tx.hash.StringLE())
|
||||
}
|
||||
|
||||
func TestDecodeEncodeInvocationTX(t *testing.T) {
|
||||
|
|
|
@ -38,7 +38,7 @@ func (u UnspentCoins) getAndUpdate(s storage.Store, hash util.Uint256) (*Unspent
|
|||
// getUnspentCoinStateFromStore retrieves UnspentCoinState from the given store
|
||||
func getUnspentCoinStateFromStore(s storage.Store, hash util.Uint256) (*UnspentCoinState, error) {
|
||||
unspent := &UnspentCoinState{}
|
||||
key := storage.AppendPrefix(storage.STCoin, hash.BytesReverse())
|
||||
key := storage.AppendPrefix(storage.STCoin, hash.BytesLE())
|
||||
if b, err := s.Get(key); err == nil {
|
||||
r := io.NewBinReaderFromBuf(b)
|
||||
unspent.DecodeBinary(r)
|
||||
|
@ -58,7 +58,7 @@ func putUnspentCoinStateIntoStore(store storage.Store, hash util.Uint256, ucs *U
|
|||
if buf.Err != nil {
|
||||
return buf.Err
|
||||
}
|
||||
key := storage.AppendPrefix(storage.STCoin, hash.BytesReverse())
|
||||
key := storage.AppendPrefix(storage.STCoin, hash.BytesLE())
|
||||
return store.Put(key, buf.Bytes())
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ func IsDoubleSpend(s storage.Store, tx *transaction.Transaction) bool {
|
|||
|
||||
for prevHash, inputs := range tx.GroupInputsByPrevHash() {
|
||||
unspent := &UnspentCoinState{}
|
||||
key := storage.AppendPrefix(storage.STCoin, prevHash.BytesReverse())
|
||||
key := storage.AppendPrefix(storage.STCoin, prevHash.BytesLE())
|
||||
if b, err := s.Get(key); err == nil {
|
||||
r := io.NewBinReaderFromBuf(b)
|
||||
unspent.DecodeBinary(r)
|
||||
|
|
|
@ -20,7 +20,7 @@ func TestGenesisBlockMainNet(t *testing.T) {
|
|||
}
|
||||
|
||||
expect := "d42561e3d30e15be6400b6df2f328e02d2bf6354c41dce433bc57687c82144bf"
|
||||
assert.Equal(t, expect, block.Hash().ReverseString())
|
||||
assert.Equal(t, expect, block.Hash().StringLE())
|
||||
}
|
||||
|
||||
func TestGetConsensusAddressMainNet(t *testing.T) {
|
||||
|
@ -51,11 +51,11 @@ func TestGetConsensusAddressMainNet(t *testing.T) {
|
|||
func TestUtilityTokenTX(t *testing.T) {
|
||||
expect := "602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7"
|
||||
tx := utilityTokenTX()
|
||||
assert.Equal(t, expect, tx.Hash().ReverseString())
|
||||
assert.Equal(t, expect, tx.Hash().StringLE())
|
||||
}
|
||||
|
||||
func TestGoverningTokenTX(t *testing.T) {
|
||||
expect := "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b"
|
||||
tx := governingTokenTX()
|
||||
assert.Equal(t, expect, tx.Hash().ReverseString())
|
||||
assert.Equal(t, expect, tx.Hash().StringLE())
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ func DoubleSha256(data []byte) util.Uint256 {
|
|||
var hash util.Uint256
|
||||
|
||||
h1 := Sha256(data)
|
||||
hash = Sha256(h1.Bytes())
|
||||
hash = Sha256(h1.BytesBE())
|
||||
return hash
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ func Hash160(data []byte) util.Uint160 {
|
|||
var hash util.Uint160
|
||||
|
||||
h1 := Sha256(data)
|
||||
h2 := RipeMD160(h1.Bytes())
|
||||
h2 := RipeMD160(h1.BytesBE())
|
||||
hash, _ = util.Uint160DecodeBytesBE(h2.BytesBE())
|
||||
|
||||
return hash
|
||||
|
|
|
@ -14,7 +14,7 @@ func TestSha256(t *testing.T) {
|
|||
data := Sha256(input)
|
||||
|
||||
expected := "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
|
||||
actual := hex.EncodeToString(data.Bytes())
|
||||
actual := hex.EncodeToString(data.BytesBE())
|
||||
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
|
@ -24,10 +24,10 @@ func TestHashDoubleSha256(t *testing.T) {
|
|||
data := DoubleSha256(input)
|
||||
|
||||
firstSha := Sha256(input)
|
||||
doubleSha := Sha256(firstSha.Bytes())
|
||||
expected := hex.EncodeToString(doubleSha.Bytes())
|
||||
doubleSha := Sha256(firstSha.BytesBE())
|
||||
expected := hex.EncodeToString(doubleSha.BytesBE())
|
||||
|
||||
actual := hex.EncodeToString(data.Bytes())
|
||||
actual := hex.EncodeToString(data.BytesBE())
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
|
|
|
@ -16,12 +16,12 @@ func TestPubKeyVerify(t *testing.T) {
|
|||
signedData, err := privKey.Sign(data)
|
||||
assert.Nil(t, err)
|
||||
pubKey := privKey.PublicKey()
|
||||
result := pubKey.Verify(signedData, hashedData.Bytes())
|
||||
result := pubKey.Verify(signedData, hashedData.BytesBE())
|
||||
expected := true
|
||||
assert.Equal(t, expected, result)
|
||||
|
||||
pubKey = &PublicKey{}
|
||||
assert.False(t, pubKey.Verify(signedData, hashedData.Bytes()))
|
||||
assert.False(t, pubKey.Verify(signedData, hashedData.BytesBE()))
|
||||
}
|
||||
|
||||
func TestWrongPubKey(t *testing.T) {
|
||||
|
@ -33,7 +33,7 @@ func TestWrongPubKey(t *testing.T) {
|
|||
secondPrivKey, _ := NewPrivateKey()
|
||||
wrongPubKey := secondPrivKey.PublicKey()
|
||||
|
||||
actual := wrongPubKey.Verify(signedData, hashedData.Bytes())
|
||||
actual := wrongPubKey.Verify(signedData, hashedData.BytesBE())
|
||||
expcted := false
|
||||
assert.Equal(t, expcted, actual)
|
||||
}
|
||||
|
|
|
@ -63,8 +63,8 @@ func buildMerkleTree(leaves []*MerkleTreeNode) (*MerkleTreeNode, error) {
|
|||
leaves[i*2+1].parent = parents[i]
|
||||
}
|
||||
|
||||
b1 := parents[i].leftChild.hash.Bytes()
|
||||
b2 := parents[i].rightChild.hash.Bytes()
|
||||
b1 := parents[i].leftChild.hash.BytesBE()
|
||||
b2 := parents[i].rightChild.hash.BytesBE()
|
||||
b1 = append(b1, b2...)
|
||||
parents[i].hash = hash.DoubleSha256(b1)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ func TestComputeMerkleTree(t *testing.T) {
|
|||
|
||||
hashes := make([]util.Uint256, len(rawHashes))
|
||||
for i, str := range rawHashes {
|
||||
hash, _ := util.Uint256DecodeReverseString(str)
|
||||
hash, _ := util.Uint256DecodeStringLE(str)
|
||||
hashes[i] = hash
|
||||
}
|
||||
|
||||
|
@ -25,5 +25,5 @@ func TestComputeMerkleTree(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, "803ff4abe3ea6533bcc0be574efa02f83ae8fdc651c879056b0d9be336c01bf4", merkle.Root().ReverseString())
|
||||
assert.Equal(t, "803ff4abe3ea6533bcc0be574efa02f83ae8fdc651c879056b0d9be336c01bf4", merkle.Root().StringLE())
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ func TestBinEncodeDecode(t *testing.T) {
|
|||
header := headerMsg.Hdrs[0]
|
||||
hash := header.Hash()
|
||||
|
||||
assert.Equal(t, "f3c4ec44c07eccbda974f1ee34bc6654ab6d3f22cd89c2e5c593a16d6cc7e6e8", hash.ReverseString())
|
||||
assert.Equal(t, "f3c4ec44c07eccbda974f1ee34bc6654ab6d3f22cd89c2e5c593a16d6cc7e6e8", hash.StringLE())
|
||||
|
||||
buf := io.NewBufBinWriter()
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ func (s NeoScanServer) CalculateInputs(address string, assetIDUint util.Uint256,
|
|||
err error
|
||||
us []*Unspent
|
||||
assetUnspent Unspent
|
||||
assetID = wrappers.GlobalAssets[assetIDUint.ReverseString()]
|
||||
assetID = wrappers.GlobalAssets[assetIDUint.StringLE()]
|
||||
)
|
||||
if us, err = s.GetBalance(address); err != nil {
|
||||
return nil, util.Fixed8(0), errs.Wrapf(err, "Cannot get balance for address %v", address)
|
||||
|
|
|
@ -75,7 +75,7 @@ func (p Param) GetUint256() (util.Uint256, error) {
|
|||
return util.Uint256{}, err
|
||||
}
|
||||
|
||||
return util.Uint256DecodeReverseString(s)
|
||||
return util.Uint256DecodeStringLE(s)
|
||||
}
|
||||
|
||||
// GetUint160FromHex returns Uint160 value of the parameter encoded in hex.
|
||||
|
|
|
@ -95,7 +95,7 @@ func TestParamGetArray(t *testing.T) {
|
|||
|
||||
func TestParamGetUint256(t *testing.T) {
|
||||
gas := "602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7"
|
||||
u256, _ := util.Uint256DecodeReverseString(gas)
|
||||
u256, _ := util.Uint256DecodeStringLE(gas)
|
||||
p := Param{stringT, gas}
|
||||
u, err := p.GetUint256()
|
||||
assert.Equal(t, u256, u)
|
||||
|
|
|
@ -148,7 +148,7 @@ func (c *Client) SendToAddress(asset util.Uint256, address string, amount util.F
|
|||
response.ID = resp.ID
|
||||
response.JSONRPC = resp.JSONRPC
|
||||
response.Result = &TxResponse{
|
||||
TxID: rawTx.Hash().ReverseString(),
|
||||
TxID: rawTx.Hash().StringLE(),
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ func (c *Client) SignAndPushInvocationTx(script []byte, wif *keys.WIF, gas util.
|
|||
var err error
|
||||
|
||||
gasIDB, _ := hex.DecodeString("602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7")
|
||||
gasID, _ := util.Uint256DecodeReverseBytes(gasIDB)
|
||||
gasID, _ := util.Uint256DecodeBytesLE(gasIDB)
|
||||
|
||||
tx := transaction.NewInvocationTX(script, gas)
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ Methods:
|
|||
switch req.Method {
|
||||
case "getbestblockhash":
|
||||
getbestblockhashCalled.Inc()
|
||||
results = "0x" + s.chain.CurrentBlockHash().ReverseString()
|
||||
results = "0x" + s.chain.CurrentBlockHash().StringLE()
|
||||
|
||||
case "getblock":
|
||||
getbestblockCalled.Inc()
|
||||
|
|
|
@ -97,7 +97,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
|||
{
|
||||
params: "[]",
|
||||
result: func(e *executor) interface{} {
|
||||
return "0x" + e.chain.CurrentBlockHash().ReverseString()
|
||||
return "0x" + e.chain.CurrentBlockHash().StringLE()
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -117,7 +117,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
|||
block, err := e.chain.GetBlock(e.chain.GetHeaderHash(1))
|
||||
require.NoErrorf(t, err, "could not get block")
|
||||
|
||||
expectedHash := "0x" + block.Hash().ReverseString()
|
||||
expectedHash := "0x" + block.Hash().StringLE()
|
||||
assert.Equal(t, expectedHash, res.Result.Hash)
|
||||
},
|
||||
},
|
||||
|
@ -164,7 +164,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
|||
block, err := e.chain.GetBlock(e.chain.GetHeaderHash(1))
|
||||
require.NoErrorf(t, err, "could not get block")
|
||||
|
||||
expectedHash := "0x" + block.Hash().ReverseString()
|
||||
expectedHash := "0x" + block.Hash().StringLE()
|
||||
assert.Equal(t, expectedHash, res.Result)
|
||||
},
|
||||
},
|
||||
|
@ -447,7 +447,7 @@ func TestRPC(t *testing.T) {
|
|||
t.Run("getrawtransaction", func(t *testing.T) {
|
||||
block, _ := chain.GetBlock(chain.GetHeaderHash(0))
|
||||
TXHash := block.Transactions[1].Hash()
|
||||
rpc := fmt.Sprintf(`{"jsonrpc": "2.0", "id": 1, "method": "getrawtransaction", "params": ["%s"]}"`, TXHash.ReverseString())
|
||||
rpc := fmt.Sprintf(`{"jsonrpc": "2.0", "id": 1, "method": "getrawtransaction", "params": ["%s"]}"`, TXHash.StringLE())
|
||||
body := doRPCCall(rpc, handler, t)
|
||||
checkErrResponse(t, body, false)
|
||||
var res StringResultResponse
|
||||
|
@ -459,7 +459,7 @@ func TestRPC(t *testing.T) {
|
|||
t.Run("getrawtransaction 2 arguments", func(t *testing.T) {
|
||||
block, _ := chain.GetBlock(chain.GetHeaderHash(0))
|
||||
TXHash := block.Transactions[1].Hash()
|
||||
rpc := fmt.Sprintf(`{"jsonrpc": "2.0", "id": 1, "method": "getrawtransaction", "params": ["%s", 0]}"`, TXHash.ReverseString())
|
||||
rpc := fmt.Sprintf(`{"jsonrpc": "2.0", "id": 1, "method": "getrawtransaction", "params": ["%s", 0]}"`, TXHash.StringLE())
|
||||
body := doRPCCall(rpc, handler, t)
|
||||
checkErrResponse(t, body, false)
|
||||
var res StringResultResponse
|
||||
|
|
|
@ -244,7 +244,7 @@ func (p StackParam) TryParse(dest interface{}) error {
|
|||
*dest = data
|
||||
return nil
|
||||
case *util.Uint256:
|
||||
if *dest, err = util.Uint256DecodeReverseBytes(data); err != nil {
|
||||
if *dest, err = util.Uint256DecodeBytesLE(data); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -202,7 +202,7 @@ func expandArrayIntoScript(script *bytes.Buffer, slice []Param) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := vm.EmitBytes(script, hash.Bytes()); err != nil {
|
||||
if err := vm.EmitBytes(script, hash.BytesBE()); err != nil {
|
||||
return err
|
||||
}
|
||||
case PublicKey:
|
||||
|
|
|
@ -35,7 +35,7 @@ func NewUnspents(a *core.AccountState, chain core.Blockchainer, addr string) Uns
|
|||
}
|
||||
balanceValues := a.GetBalanceValues()
|
||||
for k, v := range a.Balances {
|
||||
name, ok := GlobalAssets[k.ReverseString()]
|
||||
name, ok := GlobalAssets[k.StringLE()]
|
||||
if !ok {
|
||||
as := chain.GetAssetState(k)
|
||||
if as != nil {
|
||||
|
|
|
@ -16,8 +16,8 @@ const Uint256Size = 32
|
|||
// Uint256 is a 32 byte long unsigned integer.
|
||||
type Uint256 [Uint256Size]uint8
|
||||
|
||||
// Uint256DecodeReverseString attempts to decode the given string (in LE representation) into an Uint256.
|
||||
func Uint256DecodeReverseString(s string) (u Uint256, err error) {
|
||||
// Uint256DecodeStringLE attempts to decode the given string (in LE representation) into an Uint256.
|
||||
func Uint256DecodeStringLE(s string) (u Uint256, err error) {
|
||||
if len(s) != Uint256Size*2 {
|
||||
return u, fmt.Errorf("expected string size of %d got %d", Uint256Size*2, len(s))
|
||||
}
|
||||
|
@ -25,11 +25,11 @@ func Uint256DecodeReverseString(s string) (u Uint256, err error) {
|
|||
if err != nil {
|
||||
return u, err
|
||||
}
|
||||
return Uint256DecodeReverseBytes(b)
|
||||
return Uint256DecodeBytesLE(b)
|
||||
}
|
||||
|
||||
// Uint256DecodeBytes attempts to decode the given string (in BE representation) into an Uint256.
|
||||
func Uint256DecodeBytes(b []byte) (u Uint256, err error) {
|
||||
// Uint256DecodeBytesBE attempts to decode the given string (in BE representation) into an Uint256.
|
||||
func Uint256DecodeBytesBE(b []byte) (u Uint256, err error) {
|
||||
if len(b) != Uint256Size {
|
||||
return u, fmt.Errorf("expected []byte of size %d got %d", Uint256Size, len(b))
|
||||
}
|
||||
|
@ -37,26 +37,26 @@ func Uint256DecodeBytes(b []byte) (u Uint256, err error) {
|
|||
return u, nil
|
||||
}
|
||||
|
||||
// Uint256DecodeReverseBytes attempts to decode the given string (in LE representation) into an Uint256.
|
||||
func Uint256DecodeReverseBytes(b []byte) (u Uint256, err error) {
|
||||
// Uint256DecodeBytesLE attempts to decode the given string (in LE representation) into an Uint256.
|
||||
func Uint256DecodeBytesLE(b []byte) (u Uint256, err error) {
|
||||
b = ArrayReverse(b)
|
||||
return Uint256DecodeBytes(b)
|
||||
return Uint256DecodeBytesBE(b)
|
||||
}
|
||||
|
||||
// Bytes returns a byte slice representation of u.
|
||||
func (u Uint256) Bytes() []byte {
|
||||
// BytesBE returns a byte slice representation of u.
|
||||
func (u Uint256) BytesBE() []byte {
|
||||
return u[:]
|
||||
}
|
||||
|
||||
// Reverse reverses the Uint256 object
|
||||
func (u Uint256) Reverse() Uint256 {
|
||||
res, _ := Uint256DecodeReverseBytes(u.Bytes())
|
||||
res, _ := Uint256DecodeBytesLE(u.BytesBE())
|
||||
return res
|
||||
}
|
||||
|
||||
// BytesReverse return a reversed byte representation of u.
|
||||
func (u Uint256) BytesReverse() []byte {
|
||||
return ArrayReverse(u.Bytes())
|
||||
// BytesLE return a little-endian byte representation of u.
|
||||
func (u Uint256) BytesLE() []byte {
|
||||
return ArrayReverse(u.BytesBE())
|
||||
}
|
||||
|
||||
// Equals returns true if both Uint256 values are the same.
|
||||
|
@ -66,12 +66,17 @@ func (u Uint256) Equals(other Uint256) bool {
|
|||
|
||||
// String implements the stringer interface.
|
||||
func (u Uint256) String() string {
|
||||
return hex.EncodeToString(u.Bytes())
|
||||
return u.StringBE()
|
||||
}
|
||||
|
||||
// ReverseString produces string representation of Uint256 with LE byte order.
|
||||
func (u Uint256) ReverseString() string {
|
||||
return hex.EncodeToString(u.BytesReverse())
|
||||
// StringBE produces string representation of Uint256 with BE byte order.
|
||||
func (u Uint256) StringBE() string {
|
||||
return hex.EncodeToString(u.BytesBE())
|
||||
}
|
||||
|
||||
// StringLE produces string representation of Uint256 with LE byte order.
|
||||
func (u Uint256) StringLE() string {
|
||||
return hex.EncodeToString(u.BytesLE())
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the json unmarshaller interface.
|
||||
|
@ -81,13 +86,13 @@ func (u *Uint256) UnmarshalJSON(data []byte) (err error) {
|
|||
return err
|
||||
}
|
||||
js = strings.TrimPrefix(js, "0x")
|
||||
*u, err = Uint256DecodeReverseString(js)
|
||||
*u, err = Uint256DecodeStringLE(js)
|
||||
return err
|
||||
}
|
||||
|
||||
// MarshalJSON implements the json marshaller interface.
|
||||
func (u Uint256) MarshalJSON() ([]byte, error) {
|
||||
return []byte(`"0x` + u.ReverseString() + `"`), nil
|
||||
return []byte(`"0x` + u.StringLE() + `"`), nil
|
||||
}
|
||||
|
||||
// CompareTo compares two Uint256 with each other. Possible output: 1, -1, 0
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
|
||||
func TestUint256UnmarshalJSON(t *testing.T) {
|
||||
str := "f037308fa0ab18155bccfc08485468c112409ea5064595699e98c545f245f32d"
|
||||
expected, err := Uint256DecodeReverseString(str)
|
||||
expected, err := Uint256DecodeStringLE(str)
|
||||
require.NoError(t, err)
|
||||
|
||||
// UnmarshalJSON decodes hex-strings
|
||||
|
@ -33,23 +33,23 @@ func TestUint256UnmarshalJSON(t *testing.T) {
|
|||
|
||||
func TestUint256DecodeString(t *testing.T) {
|
||||
hexStr := "f037308fa0ab18155bccfc08485468c112409ea5064595699e98c545f245f32d"
|
||||
val, err := Uint256DecodeReverseString(hexStr)
|
||||
val, err := Uint256DecodeStringLE(hexStr)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, hexStr, val.ReverseString())
|
||||
assert.Equal(t, hexStr, val.StringLE())
|
||||
|
||||
bs, err := hex.DecodeString(hexStr)
|
||||
require.NoError(t, err)
|
||||
|
||||
val1, err := Uint256DecodeBytes(bs)
|
||||
val1, err := Uint256DecodeBytesBE(bs)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, hexStr, val1.String())
|
||||
assert.Equal(t, val, val1.Reverse())
|
||||
|
||||
_, err = Uint256DecodeReverseString(hexStr[1:])
|
||||
_, err = Uint256DecodeStringLE(hexStr[1:])
|
||||
assert.Error(t, err)
|
||||
|
||||
hexStr = "zzz7308fa0ab18155bccfc08485468c112409ea5064595699e98c545f245f32d"
|
||||
_, err = Uint256DecodeReverseString(hexStr)
|
||||
_, err = Uint256DecodeStringLE(hexStr)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
|
@ -58,11 +58,11 @@ func TestUint256DecodeBytes(t *testing.T) {
|
|||
b, err := hex.DecodeString(hexStr)
|
||||
require.NoError(t, err)
|
||||
|
||||
val, err := Uint256DecodeReverseBytes(b)
|
||||
val, err := Uint256DecodeBytesLE(b)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, hexStr, val.ReverseString())
|
||||
assert.Equal(t, hexStr, val.StringLE())
|
||||
|
||||
_, err = Uint256DecodeBytes(b[1:])
|
||||
_, err = Uint256DecodeBytesBE(b[1:])
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
|
@ -70,10 +70,10 @@ func TestUInt256Equals(t *testing.T) {
|
|||
a := "f037308fa0ab18155bccfc08485468c112409ea5064595699e98c545f245f32d"
|
||||
b := "e287c5b29a1b66092be6803c59c765308ac20287e1b4977fd399da5fc8f66ab5"
|
||||
|
||||
ua, err := Uint256DecodeReverseString(a)
|
||||
ua, err := Uint256DecodeStringLE(a)
|
||||
require.NoError(t, err)
|
||||
|
||||
ub, err := Uint256DecodeReverseString(b)
|
||||
ub, err := Uint256DecodeStringLE(b)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, ua.Equals(ub), "%s and %s cannot be equal", ua, ub)
|
||||
assert.True(t, ua.Equals(ua), "%s and %s must be equal", ua, ua)
|
||||
|
|
|
@ -1166,7 +1166,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
|||
hashToCheck = v.checkhash
|
||||
} else { // VERIFY
|
||||
msg := v.estack.Pop().Bytes()
|
||||
hashToCheck = hash.Sha256(msg).Bytes()
|
||||
hashToCheck = hash.Sha256(msg).BytesBE()
|
||||
}
|
||||
pkey := &keys.PublicKey{}
|
||||
err := pkey.DecodeBytes(keyb)
|
||||
|
@ -1292,7 +1292,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
|||
|
||||
case opcode.SHA256:
|
||||
b := v.estack.Pop().Bytes()
|
||||
v.estack.PushVal(hash.Sha256(b).Bytes())
|
||||
v.estack.PushVal(hash.Sha256(b).BytesBE())
|
||||
|
||||
case opcode.HASH160:
|
||||
b := v.estack.Pop().Bytes()
|
||||
|
@ -1300,7 +1300,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
|||
|
||||
case opcode.HASH256:
|
||||
b := v.estack.Pop().Bytes()
|
||||
v.estack.PushVal(hash.DoubleSha256(b).Bytes())
|
||||
v.estack.PushVal(hash.DoubleSha256(b).BytesBE())
|
||||
|
||||
case opcode.NOP:
|
||||
// unlucky ^^
|
||||
|
|
|
@ -2198,7 +2198,7 @@ func TestCHECKSIGBadKey(t *testing.T) {
|
|||
assert.Nil(t, err)
|
||||
pbytes := pk.PublicKey().Bytes()[:4]
|
||||
vm := load(prog)
|
||||
vm.SetCheckedHash(hash.Sha256(msg).Bytes())
|
||||
vm.SetCheckedHash(hash.Sha256(msg).BytesBE())
|
||||
vm.estack.PushVal(sig)
|
||||
vm.estack.PushVal(pbytes)
|
||||
checkVMFailed(t, vm)
|
||||
|
@ -2213,7 +2213,7 @@ func TestCHECKSIGWrongSig(t *testing.T) {
|
|||
assert.Nil(t, err)
|
||||
pbytes := pk.PublicKey().Bytes()
|
||||
vm := load(prog)
|
||||
vm.SetCheckedHash(hash.Sha256(msg).Bytes())
|
||||
vm.SetCheckedHash(hash.Sha256(msg).BytesBE())
|
||||
vm.estack.PushVal(util.ArrayReverse(sig))
|
||||
vm.estack.PushVal(pbytes)
|
||||
runVM(t, vm)
|
||||
|
@ -2230,7 +2230,7 @@ func TestCHECKSIGGood(t *testing.T) {
|
|||
assert.Nil(t, err)
|
||||
pbytes := pk.PublicKey().Bytes()
|
||||
vm := load(prog)
|
||||
vm.SetCheckedHash(hash.Sha256(msg).Bytes())
|
||||
vm.SetCheckedHash(hash.Sha256(msg).BytesBE())
|
||||
vm.estack.PushVal(sig)
|
||||
vm.estack.PushVal(pbytes)
|
||||
runVM(t, vm)
|
||||
|
@ -2301,7 +2301,7 @@ func TestCHECKMULTISIGNotEnoughKeys(t *testing.T) {
|
|||
assert.Nil(t, err)
|
||||
pbytes1 := pk1.PublicKey().Bytes()
|
||||
vm := load(prog)
|
||||
vm.SetCheckedHash(hash.Sha256(msg).Bytes())
|
||||
vm.SetCheckedHash(hash.Sha256(msg).BytesBE())
|
||||
vm.estack.PushVal([]StackItem{NewByteArrayItem(sig1), NewByteArrayItem(sig2)})
|
||||
vm.estack.PushVal([]StackItem{NewByteArrayItem(pbytes1)})
|
||||
checkVMFailed(t, vm)
|
||||
|
@ -2340,7 +2340,7 @@ func TestCHECKMULTISIGBadKey(t *testing.T) {
|
|||
pbytes1 := pk1.PublicKey().Bytes()
|
||||
pbytes2 := pk2.PublicKey().Bytes()[:4]
|
||||
vm := load(prog)
|
||||
vm.SetCheckedHash(hash.Sha256(msg).Bytes())
|
||||
vm.SetCheckedHash(hash.Sha256(msg).BytesBE())
|
||||
vm.estack.PushVal([]StackItem{NewByteArrayItem(sig1), NewByteArrayItem(sig2)})
|
||||
vm.estack.PushVal([]StackItem{NewByteArrayItem(pbytes1), NewByteArrayItem(pbytes2)})
|
||||
checkVMFailed(t, vm)
|
||||
|
@ -2360,7 +2360,7 @@ func TestCHECKMULTISIGBadSig(t *testing.T) {
|
|||
pbytes1 := pk1.PublicKey().Bytes()
|
||||
pbytes2 := pk2.PublicKey().Bytes()
|
||||
vm := load(prog)
|
||||
vm.SetCheckedHash(hash.Sha256(msg).Bytes())
|
||||
vm.SetCheckedHash(hash.Sha256(msg).BytesBE())
|
||||
vm.estack.PushVal([]StackItem{NewByteArrayItem(util.ArrayReverse(sig1)), NewByteArrayItem(sig2)})
|
||||
vm.estack.PushVal([]StackItem{NewByteArrayItem(pbytes1), NewByteArrayItem(pbytes2)})
|
||||
runVM(t, vm)
|
||||
|
@ -2382,7 +2382,7 @@ func TestCHECKMULTISIGGood(t *testing.T) {
|
|||
pbytes1 := pk1.PublicKey().Bytes()
|
||||
pbytes2 := pk2.PublicKey().Bytes()
|
||||
vm := load(prog)
|
||||
vm.SetCheckedHash(hash.Sha256(msg).Bytes())
|
||||
vm.SetCheckedHash(hash.Sha256(msg).BytesBE())
|
||||
vm.estack.PushVal([]StackItem{NewByteArrayItem(sig1), NewByteArrayItem(sig2)})
|
||||
vm.estack.PushVal([]StackItem{NewByteArrayItem(pbytes1), NewByteArrayItem(pbytes2)})
|
||||
runVM(t, vm)
|
||||
|
|
Loading…
Reference in a new issue