Merge pull request #520 from nspcc-dev/fix/uint
util: refactor uint160/uint256 for endianness consistency Closes #314.
This commit is contained in:
commit
86239dd668
54 changed files with 327 additions and 226 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).ReverseString())
|
||||
fmt.Printf("Sent deployment transaction %s for contract %s\n", txHash.StringLE(), hash.Hash160(avm).StringLE())
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -670,7 +670,7 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
|
|||
c.prog.Err = err
|
||||
return
|
||||
}
|
||||
bytes := uint160.Bytes()
|
||||
bytes := uint160.BytesBE()
|
||||
emitBytes(c.prog.BinWriter, bytes)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ func (a Accounts) getAndUpdate(s storage.Store, hash util.Uint160) (*AccountStat
|
|||
// present there. Returns nil otherwise.
|
||||
func getAccountStateFromStore(s storage.Store, hash util.Uint160) (*AccountState, error) {
|
||||
var account *AccountState
|
||||
key := storage.AppendPrefix(storage.STAccount, hash.Bytes())
|
||||
key := storage.AppendPrefix(storage.STAccount, hash.BytesBE())
|
||||
b, err := s.Get(key)
|
||||
if err == nil {
|
||||
account = new(AccountState)
|
||||
|
@ -55,7 +55,7 @@ func putAccountStateIntoStore(store storage.Store, as *AccountState) error {
|
|||
if buf.Err != nil {
|
||||
return buf.Err
|
||||
}
|
||||
key := storage.AppendPrefix(storage.STAccount, as.ScriptHash.Bytes())
|
||||
key := storage.AppendPrefix(storage.STAccount, as.ScriptHash.BytesBE())
|
||||
return store.Put(key, buf.Bytes())
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
@ -602,7 +602,7 @@ func processValidatorStateDescriptor(descriptor *transaction.StateDescriptor, st
|
|||
}
|
||||
|
||||
func processAccountStateDescriptor(descriptor *transaction.StateDescriptor, state *BlockChainState) error {
|
||||
hash, err := util.Uint160DecodeBytes(descriptor.Key)
|
||||
hash, err := util.Uint160DecodeBytesBE(descriptor.Key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -744,7 +744,7 @@ func (bc *Blockchain) GetStorageItems(hash util.Uint160) (map[string]*StorageIte
|
|||
// Cut prefix and hash.
|
||||
siMap[string(k[21:])] = si
|
||||
}
|
||||
bc.store.Seek(storage.AppendPrefix(storage.STStorage, hash.BytesReverse()), saveToMap)
|
||||
bc.store.Seek(storage.AppendPrefix(storage.STStorage, hash.BytesLE()), saveToMap)
|
||||
if err != nil {
|
||||
return nil, 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
|
||||
|
@ -893,7 +893,7 @@ func (bc *Blockchain) GetContractState(hash util.Uint160) *ContractState {
|
|||
// getContractStateFromStore returns contract state as recorded in the given
|
||||
// store by the given script hash.
|
||||
func getContractStateFromStore(s storage.Store, hash util.Uint160) *ContractState {
|
||||
key := storage.AppendPrefix(storage.STContract, hash.Bytes())
|
||||
key := storage.AppendPrefix(storage.STContract, hash.BytesBE())
|
||||
contractBytes, 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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1366,7 +1366,7 @@ func (bc *Blockchain) GetScriptHashesForVerifying(t *transaction.Transaction) ([
|
|||
}
|
||||
for _, a := range t.Attributes {
|
||||
if a.Usage == transaction.Script {
|
||||
h, err := util.Uint160DecodeBytes(a.Data)
|
||||
h, err := util.Uint160DecodeBytesBE(a.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
|
|
|
@ -70,13 +70,13 @@ func putContractStateIntoStore(s storage.Store, cs *ContractState) error {
|
|||
if buf.Err != nil {
|
||||
return buf.Err
|
||||
}
|
||||
key := storage.AppendPrefix(storage.STContract, cs.ScriptHash().Bytes())
|
||||
key := storage.AppendPrefix(storage.STContract, cs.ScriptHash().BytesBE())
|
||||
return s.Put(key, buf.Bytes())
|
||||
}
|
||||
|
||||
// deleteContractStateInStore deletes given contract state in the given store.
|
||||
func deleteContractStateInStore(s storage.Store, hash util.Uint160) error {
|
||||
key := storage.AppendPrefix(storage.STContract, hash.Bytes())
|
||||
key := storage.AppendPrefix(storage.STContract, hash.BytesBE())
|
||||
return s.Delete(key)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ func (ic *interopContext) headerGetNextConsensus(v *vm.VM) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.Estack().PushVal(header.NextConsensus.BytesReverse())
|
||||
v.Estack().PushVal(header.NextConsensus.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
|
||||
}
|
||||
|
||||
|
@ -271,7 +271,7 @@ func (ic *interopContext) outputGetScriptHash(v *vm.VM) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.Estack().PushVal(output.ScriptHash.Bytes())
|
||||
v.Estack().PushVal(output.ScriptHash.BytesBE())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -310,7 +310,7 @@ func (ic *interopContext) attrGetUsage(v *vm.VM) error {
|
|||
// bcGetAccount returns or creates an account.
|
||||
func (ic *interopContext) bcGetAccount(v *vm.VM) error {
|
||||
accbytes := v.Estack().Pop().Bytes()
|
||||
acchash, err := util.Uint160DecodeBytes(accbytes)
|
||||
acchash, err := util.Uint160DecodeBytesBE(accbytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -364,7 +364,7 @@ func (ic *interopContext) accountGetScriptHash(v *vm.VM) error {
|
|||
if !ok {
|
||||
return fmt.Errorf("%T is not an account state", acc)
|
||||
}
|
||||
v.Estack().PushVal(acc.ScriptHash.Bytes())
|
||||
v.Estack().PushVal(acc.ScriptHash.BytesBE())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -389,7 +389,7 @@ func (ic *interopContext) accountGetVotes(v *vm.VM) error {
|
|||
// accountIsStandard checks whether given account is standard.
|
||||
func (ic *interopContext) accountIsStandard(v *vm.VM) error {
|
||||
accbytes := v.Estack().Pop().Bytes()
|
||||
acchash, err := util.Uint160DecodeBytes(accbytes)
|
||||
acchash, err := util.Uint160DecodeBytesBE(accbytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -601,11 +601,11 @@ func (ic *interopContext) assetCreate(v *vm.VM) error {
|
|||
if !witnessOk {
|
||||
return errors.New("witness check didn't succeed")
|
||||
}
|
||||
admin, err := util.Uint160DecodeBytes(v.Estack().Pop().Bytes())
|
||||
admin, err := util.Uint160DecodeBytesBE(v.Estack().Pop().Bytes())
|
||||
if err != nil {
|
||||
return gherr.Wrap(err, "failed to get admin")
|
||||
}
|
||||
issuer, err := util.Uint160DecodeBytes(v.Estack().Pop().Bytes())
|
||||
issuer, err := util.Uint160DecodeBytesBE(v.Estack().Pop().Bytes())
|
||||
if err != nil {
|
||||
return gherr.Wrap(err, "failed to get issuer")
|
||||
}
|
||||
|
@ -635,7 +635,7 @@ func (ic *interopContext) assetGetAdmin(v *vm.VM) error {
|
|||
if !ok {
|
||||
return fmt.Errorf("%T is not an asset state", as)
|
||||
}
|
||||
v.Estack().PushVal(as.Admin.Bytes())
|
||||
v.Estack().PushVal(as.Admin.BytesBE())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -690,7 +690,7 @@ func (ic *interopContext) assetGetIssuer(v *vm.VM) error {
|
|||
if !ok {
|
||||
return fmt.Errorf("%T is not an asset state", as)
|
||||
}
|
||||
v.Estack().PushVal(as.Issuer.Bytes())
|
||||
v.Estack().PushVal(as.Issuer.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) {
|
||||
|
@ -74,7 +74,7 @@ func TestHeaderGetNextConsensus(t *testing.T) {
|
|||
err := context.headerGetNextConsensus(v)
|
||||
require.NoError(t, err)
|
||||
value := v.Estack().Pop().Value()
|
||||
require.Equal(t, block.NextConsensus.BytesReverse(), value)
|
||||
require.Equal(t, block.NextConsensus.BytesLE(), value)
|
||||
}
|
||||
|
||||
func TestTxGetAttributes(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) {
|
||||
|
@ -168,7 +168,7 @@ func TestOutputGetScriptHash(t *testing.T) {
|
|||
err := context.outputGetScriptHash(v)
|
||||
require.NoError(t, err)
|
||||
scriptHash := v.Estack().Pop().Value()
|
||||
require.Equal(t, tx.Outputs[0].ScriptHash.Bytes(), scriptHash)
|
||||
require.Equal(t, tx.Outputs[0].ScriptHash.BytesBE(), scriptHash)
|
||||
}
|
||||
|
||||
func TestOutputGetValue(t *testing.T) {
|
||||
|
@ -208,7 +208,7 @@ func TestAccountGetScriptHash(t *testing.T) {
|
|||
err := context.accountGetScriptHash(v)
|
||||
require.NoError(t, err)
|
||||
hash := v.Estack().Pop().Value()
|
||||
require.Equal(t, accState.ScriptHash.Bytes(), hash)
|
||||
require.Equal(t, accState.ScriptHash.BytesBE(), hash)
|
||||
}
|
||||
|
||||
func TestAccountGetVotes(t *testing.T) {
|
||||
|
@ -248,7 +248,7 @@ func TestAssetGetAdmin(t *testing.T) {
|
|||
err := context.assetGetAdmin(v)
|
||||
require.NoError(t, err)
|
||||
admin := v.Estack().Pop().Value()
|
||||
require.Equal(t, assetState.Admin.Bytes(), admin)
|
||||
require.Equal(t, assetState.Admin.BytesBE(), admin)
|
||||
}
|
||||
|
||||
func TestAssetGetAmount(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) {
|
||||
|
@ -298,7 +298,7 @@ func TestAssetGetIssuer(t *testing.T) {
|
|||
err := context.assetGetIssuer(v)
|
||||
require.NoError(t, err)
|
||||
issuer := v.Estack().Pop().Value()
|
||||
require.Equal(t, assetState.Issuer.Bytes(), issuer)
|
||||
require.Equal(t, assetState.Issuer.BytesBE(), issuer)
|
||||
}
|
||||
|
||||
func TestAssetGetOwner(t *testing.T) {
|
||||
|
@ -381,7 +381,7 @@ func createVMAndContractState(t *testing.T) (*vm.VM, *ContractState, *interopCon
|
|||
func createVMAndAccState(t *testing.T) (*vm.VM, *AccountState, *interopContext) {
|
||||
v := vm.New()
|
||||
rawHash := "4d3b96ae1bcc5a585e075e3b81920210dec16302"
|
||||
hash, err := util.Uint160DecodeString(rawHash)
|
||||
hash, err := util.Uint160DecodeStringBE(rawHash)
|
||||
accountState := NewAccountState(hash)
|
||||
|
||||
key := &keys.PublicKey{X: big.NewInt(1), Y: big.NewInt(1)}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ func (ic *interopContext) bcGetBlock(v *vm.VM) error {
|
|||
// bcGetContract returns contract.
|
||||
func (ic *interopContext) bcGetContract(v *vm.VM) error {
|
||||
hashbytes := v.Estack().Pop().Bytes()
|
||||
hash, err := util.Uint160DecodeBytes(hashbytes)
|
||||
hash, err := util.Uint160DecodeBytesBE(hashbytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -260,7 +260,7 @@ func getContextScriptHash(v *vm.VM, n int) util.Uint160 {
|
|||
// invocation stack element number n.
|
||||
func pushContextScriptHash(v *vm.VM, n int) error {
|
||||
h := getContextScriptHash(v, n)
|
||||
v.Estack().PushVal(h.Bytes())
|
||||
v.Estack().PushVal(h.BytesBE())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -318,7 +318,7 @@ func (ic *interopContext) runtimeCheckWitness(v *vm.VM) error {
|
|||
var err error
|
||||
|
||||
hashOrKey := v.Estack().Pop().Bytes()
|
||||
hash, err := util.Uint160DecodeBytes(hashOrKey)
|
||||
hash, err := util.Uint160DecodeBytesBE(hashOrKey)
|
||||
if err != nil {
|
||||
key := &keys.PublicKey{}
|
||||
err = key.DecodeBytes(hashOrKey)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ type StorageItem struct {
|
|||
|
||||
// makeStorageItemKey returns a key used to store StorageItem in the DB.
|
||||
func makeStorageItemKey(scripthash util.Uint160, key []byte) []byte {
|
||||
return storage.AppendPrefix(storage.STStorage, append(scripthash.BytesReverse(), key...))
|
||||
return storage.AppendPrefix(storage.STStorage, append(scripthash.BytesLE(), key...))
|
||||
}
|
||||
|
||||
// getStorageItemFromStore returns StorageItem if it exists in the given Store.
|
||||
|
|
|
@ -14,7 +14,7 @@ func TestPutGetDeleteStorageItem(t *testing.T) {
|
|||
Value: []byte("smth"),
|
||||
}
|
||||
key := []byte("key")
|
||||
cHash, err := util.Uint160DecodeBytes([]byte("abcdefghijklmnopqrst"))
|
||||
cHash, err := util.Uint160DecodeBytesBE([]byte("abcdefghijklmnopqrst"))
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, putStorageItemIntoStore(s, cHash, key, si))
|
||||
siRead := getStorageItemFromStore(s, cHash, key)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
func TestRegisterTX(t *testing.T) {
|
||||
someuint160, _ := util.Uint160DecodeString("4d3b96ae1bcc5a585e075e3b81920210dec16302")
|
||||
someuint160, _ := util.Uint160DecodeStringBE("4d3b96ae1bcc5a585e075e3b81920210dec16302")
|
||||
tx := &Transaction{
|
||||
Type: RegisterType,
|
||||
Version: 0,
|
||||
|
@ -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())
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
// Uint160.
|
||||
func AddressFromUint160(u util.Uint160) string {
|
||||
// Dont forget to prepend the Address version 0x17 (23) A
|
||||
b := append([]byte{0x17}, u.Bytes()...)
|
||||
b := append([]byte{0x17}, u.BytesBE()...)
|
||||
return Base58CheckEncode(b)
|
||||
}
|
||||
|
||||
|
@ -19,5 +19,5 @@ func Uint160DecodeAddress(s string) (u util.Uint160, err error) {
|
|||
if err != nil {
|
||||
return u, err
|
||||
}
|
||||
return util.Uint160DecodeBytes(b[1:21])
|
||||
return util.Uint160DecodeBytesBE(b[1:21])
|
||||
}
|
||||
|
|
|
@ -29,6 +29,6 @@ func TestUint160DecodeKnownAddress(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, "b28427088a3729b2536d10122960394e8be6721f", val.ReverseString())
|
||||
assert.Equal(t, "b28427088a3729b2536d10122960394e8be6721f", val.StringLE())
|
||||
assert.Equal(t, "1f72e68b4e39602912106d53b229378a082784b2", val.String())
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ func RipeMD160(data []byte) util.Uint160 {
|
|||
hasher := ripemd160.New()
|
||||
_, _ = hasher.Write(data)
|
||||
|
||||
hash, _ = util.Uint160DecodeBytes(hasher.Sum(nil))
|
||||
hash, _ = util.Uint160DecodeBytesBE(hasher.Sum(nil))
|
||||
return hash
|
||||
}
|
||||
|
||||
|
@ -40,8 +40,8 @@ func Hash160(data []byte) util.Uint160 {
|
|||
var hash util.Uint160
|
||||
|
||||
h1 := Sha256(data)
|
||||
h2 := RipeMD160(h1.Bytes())
|
||||
hash, _ = util.Uint160DecodeBytes(h2.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)
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ func TestHashRipeMD160(t *testing.T) {
|
|||
data := RipeMD160(input)
|
||||
|
||||
expected := "108f07b8382412612c048d07d13f814118445acd"
|
||||
actual := hex.EncodeToString(data.Bytes())
|
||||
actual := hex.EncodeToString(data.BytesBE())
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ func TestHash160(t *testing.T) {
|
|||
data := Hash160(publicKeyBytes)
|
||||
|
||||
expected := "c8e2b685cc70ec96743b55beb9449782f8f775d8"
|
||||
actual := hex.EncodeToString(data.Bytes())
|
||||
actual := hex.EncodeToString(data.BytesBE())
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
|
|
|
@ -237,7 +237,7 @@ func (p *PublicKey) GetVerificationScript() []byte {
|
|||
func (p *PublicKey) Signature() []byte {
|
||||
sig := hash.Hash160(p.GetVerificationScript())
|
||||
|
||||
return sig.Bytes()
|
||||
return sig.BytesBE()
|
||||
}
|
||||
|
||||
// Address returns a base58-encoded NEO-specific address based on the key hash.
|
||||
|
|
|
@ -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.
|
||||
|
@ -85,11 +85,11 @@ func (p Param) GetUint160FromHex() (util.Uint160, error) {
|
|||
return util.Uint160{}, err
|
||||
}
|
||||
|
||||
scriptHashLE, err := util.Uint160DecodeString(s)
|
||||
scriptHashLE, err := util.Uint160DecodeStringBE(s)
|
||||
if err != nil {
|
||||
return util.Uint160{}, err
|
||||
}
|
||||
return util.Uint160DecodeBytes(scriptHashLE.BytesReverse())
|
||||
return util.Uint160DecodeBytesBE(scriptHashLE.BytesLE())
|
||||
}
|
||||
|
||||
// GetUint160FromAddress returns Uint160 value of the parameter that was
|
||||
|
|
|
@ -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)
|
||||
|
@ -112,8 +112,8 @@ func TestParamGetUint256(t *testing.T) {
|
|||
|
||||
func TestParamGetUint160FromHex(t *testing.T) {
|
||||
in := "50befd26fdf6e4d957c11e078b24ebce6291456f"
|
||||
u160, _ := util.Uint160DecodeString(in)
|
||||
u160, _ = util.Uint160DecodeBytes(util.ArrayReverse(u160[:]))
|
||||
u160, _ := util.Uint160DecodeStringBE(in)
|
||||
u160, _ = util.Uint160DecodeBytesBE(util.ArrayReverse(u160[:]))
|
||||
p := Param{stringT, in}
|
||||
u, err := p.GetUint160FromHex()
|
||||
assert.Equal(t, u160, 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
|
||||
|
|
|
@ -236,7 +236,7 @@ func (p StackParam) TryParse(dest interface{}) error {
|
|||
}
|
||||
switch dest := dest.(type) {
|
||||
case *util.Uint160:
|
||||
if *dest, err = util.Uint160DecodeBytes(data); err != nil {
|
||||
if *dest, err = util.Uint160DecodeBytesBE(data); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -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
|
||||
|
|
|
@ -157,11 +157,11 @@ func TestStackParam_TryParse(t *testing.T) {
|
|||
params := StackParams{
|
||||
{
|
||||
Type: ByteArray,
|
||||
Value: exp1.Bytes(),
|
||||
Value: exp1.BytesBE(),
|
||||
},
|
||||
{
|
||||
Type: ByteArray,
|
||||
Value: exp2.Bytes(),
|
||||
Value: exp2.BytesBE(),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ func CreateRawContractTransaction(params ContractTxParams) (*transaction.Transac
|
|||
tx.Attributes = append(tx.Attributes,
|
||||
&transaction.Attribute{
|
||||
Usage: transaction.Script,
|
||||
Data: fromAddressHash.Bytes(),
|
||||
Data: fromAddressHash.BytesBE(),
|
||||
})
|
||||
|
||||
if err = AddInputsAndUnspentsToTx(tx, fromAddress, assetID, amount, balancer); err != nil {
|
||||
|
@ -194,7 +194,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 Hash256:
|
||||
|
@ -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:
|
||||
|
|
|
@ -45,7 +45,7 @@ func NewAccountState(a *core.AccountState) AccountState {
|
|||
sort.Sort(balances)
|
||||
|
||||
// reverse scriptHash to be consistent with other client
|
||||
scriptHash, err := util.Uint160DecodeBytes(a.ScriptHash.BytesReverse())
|
||||
scriptHash, err := util.Uint160DecodeBytesBE(a.ScriptHash.BytesLE())
|
||||
if err != nil {
|
||||
scriptHash = a.ScriptHash
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -158,7 +158,7 @@ func adjustValToType(typ ParamType, val string) (interface{}, error) {
|
|||
case Hash160Type:
|
||||
u, err := crypto.Uint160DecodeAddress(val)
|
||||
if err == nil {
|
||||
return hex.EncodeToString(u.Bytes()), nil
|
||||
return hex.EncodeToString(u.BytesBE()), nil
|
||||
}
|
||||
b, err := hex.DecodeString(val)
|
||||
if err != nil {
|
||||
|
|
|
@ -7,51 +7,96 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
const uint160Size = 20
|
||||
// Uint160Size is the size of Uint160 in bytes.
|
||||
const Uint160Size = 20
|
||||
|
||||
// Uint160 is a 20 byte long unsigned integer.
|
||||
type Uint160 [uint160Size]uint8
|
||||
type Uint160 [Uint160Size]uint8
|
||||
|
||||
// Uint160DecodeString attempts to decode the given string into an Uint160.
|
||||
func Uint160DecodeString(s string) (Uint160, error) {
|
||||
// Uint160DecodeStringBE attempts to decode the given string into an Uint160.
|
||||
func Uint160DecodeStringBE(s string) (Uint160, error) {
|
||||
var u Uint160
|
||||
if len(s) != uint160Size*2 {
|
||||
return u, fmt.Errorf("expected string size of %d got %d", uint160Size*2, len(s))
|
||||
if len(s) != Uint160Size*2 {
|
||||
return u, fmt.Errorf("expected string size of %d got %d", Uint160Size*2, len(s))
|
||||
}
|
||||
b, err := hex.DecodeString(s)
|
||||
if err != nil {
|
||||
return u, err
|
||||
}
|
||||
return Uint160DecodeBytes(b)
|
||||
return Uint160DecodeBytesBE(b)
|
||||
}
|
||||
|
||||
// Uint160DecodeBytes attempts to decode the given bytes into an Uint160.
|
||||
func Uint160DecodeBytes(b []byte) (u Uint160, err error) {
|
||||
if len(b) != uint160Size {
|
||||
return u, fmt.Errorf("expected byte size of %d got %d", uint160Size, len(b))
|
||||
// Uint160DecodeStringLE attempts to decode the given string
|
||||
// in little-endian hex encoding into an Uint160.
|
||||
func Uint160DecodeStringLE(s string) (Uint160, error) {
|
||||
var u Uint160
|
||||
if len(s) != Uint160Size*2 {
|
||||
return u, fmt.Errorf("expected string size of %d got %d", Uint160Size*2, len(s))
|
||||
}
|
||||
|
||||
b, err := hex.DecodeString(s)
|
||||
if err != nil {
|
||||
return u, err
|
||||
}
|
||||
|
||||
return Uint160DecodeBytesLE(b)
|
||||
}
|
||||
|
||||
// Uint160DecodeBytesBE attempts to decode the given bytes into an Uint160.
|
||||
func Uint160DecodeBytesBE(b []byte) (u Uint160, err error) {
|
||||
if len(b) != Uint160Size {
|
||||
return u, fmt.Errorf("expected byte size of %d got %d", Uint160Size, len(b))
|
||||
}
|
||||
copy(u[:], b)
|
||||
return
|
||||
}
|
||||
|
||||
// Bytes returns the byte slice representation of u.
|
||||
func (u Uint160) Bytes() []byte {
|
||||
// Uint160DecodeBytesLE attempts to decode the given bytes in little-endian
|
||||
// into an Uint160.
|
||||
func Uint160DecodeBytesLE(b []byte) (u Uint160, err error) {
|
||||
if len(b) != Uint160Size {
|
||||
return u, fmt.Errorf("expected byte size of %d got %d", Uint160Size, len(b))
|
||||
}
|
||||
|
||||
for i := range b {
|
||||
u[Uint160Size-i-1] = b[i]
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// BytesBE returns a big-endian byte representation of u.
|
||||
func (u Uint160) BytesBE() []byte {
|
||||
return u[:]
|
||||
}
|
||||
|
||||
// BytesReverse returns a reversed byte representation of u.
|
||||
func (u Uint160) BytesReverse() []byte {
|
||||
return ArrayReverse(u.Bytes())
|
||||
// BytesLE returns a little-endian byte representation of u.
|
||||
func (u Uint160) BytesLE() []byte {
|
||||
return ArrayReverse(u.BytesBE())
|
||||
}
|
||||
|
||||
// String implements the stringer interface.
|
||||
func (u Uint160) String() string {
|
||||
return hex.EncodeToString(u.Bytes())
|
||||
return u.StringBE()
|
||||
}
|
||||
|
||||
// ReverseString is the same as String, but returns a reversed representation.
|
||||
func (u Uint160) ReverseString() string {
|
||||
return hex.EncodeToString(u.BytesReverse())
|
||||
// StringBE returns string representations of u with big-endian byte order.
|
||||
func (u Uint160) StringBE() string {
|
||||
return hex.EncodeToString(u.BytesBE())
|
||||
}
|
||||
|
||||
// StringLE returns string representations of u with little-endian byte order.
|
||||
func (u Uint160) StringLE() string {
|
||||
return hex.EncodeToString(u.BytesLE())
|
||||
}
|
||||
|
||||
// Reverse returns reversed representation of u.
|
||||
func (u Uint160) Reverse() (r Uint160) {
|
||||
for i := 0; i < Uint160Size; i++ {
|
||||
r[i] = u[Uint160Size-i-1]
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Equals returns true if both Uint256 values are the same.
|
||||
|
@ -78,7 +123,7 @@ func (u *Uint160) UnmarshalJSON(data []byte) (err error) {
|
|||
return err
|
||||
}
|
||||
js = strings.TrimPrefix(js, "0x")
|
||||
*u, err = Uint160DecodeString(js)
|
||||
*u, err = Uint160DecodeStringBE(js)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
|
||||
func TestUint160UnmarshalJSON(t *testing.T) {
|
||||
str := "2d3b96ae1bcc5a585e075e3b81920210dec16302"
|
||||
expected, err := Uint160DecodeString(str)
|
||||
expected, err := Uint160DecodeStringBE(str)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// UnmarshalJSON decodes hex-strings
|
||||
|
@ -31,15 +31,25 @@ func TestUint160UnmarshalJSON(t *testing.T) {
|
|||
|
||||
func TestUInt160DecodeString(t *testing.T) {
|
||||
hexStr := "2d3b96ae1bcc5a585e075e3b81920210dec16302"
|
||||
val, err := Uint160DecodeString(hexStr)
|
||||
val, err := Uint160DecodeStringBE(hexStr)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, hexStr, val.String())
|
||||
|
||||
_, err = Uint160DecodeString(hexStr[1:])
|
||||
valLE, err := Uint160DecodeStringLE(hexStr)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, val, valLE.Reverse())
|
||||
|
||||
_, err = Uint160DecodeStringBE(hexStr[1:])
|
||||
assert.Error(t, err)
|
||||
|
||||
_, err = Uint160DecodeStringLE(hexStr[1:])
|
||||
assert.Error(t, err)
|
||||
|
||||
hexStr = "zz3b96ae1bcc5a585e075e3b81920210dec16302"
|
||||
_, err = Uint160DecodeString(hexStr)
|
||||
_, err = Uint160DecodeStringBE(hexStr)
|
||||
assert.Error(t, err)
|
||||
|
||||
_, err = Uint160DecodeStringLE(hexStr)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
|
@ -48,11 +58,18 @@ func TestUint160DecodeBytes(t *testing.T) {
|
|||
b, err := hex.DecodeString(hexStr)
|
||||
require.NoError(t, err)
|
||||
|
||||
val, err := Uint160DecodeBytes(b)
|
||||
val, err := Uint160DecodeBytesBE(b)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, hexStr, val.String())
|
||||
|
||||
_, err = Uint160DecodeBytes(b[1:])
|
||||
valLE, err := Uint160DecodeBytesLE(b)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, val, valLE.Reverse())
|
||||
|
||||
_, err = Uint160DecodeBytesLE(b[1:])
|
||||
assert.Error(t, err)
|
||||
|
||||
_, err = Uint160DecodeBytesBE(b[1:])
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
|
@ -60,10 +77,10 @@ func TestUInt160Equals(t *testing.T) {
|
|||
a := "2d3b96ae1bcc5a585e075e3b81920210dec16302"
|
||||
b := "4d3b96ae1bcc5a585e075e3b81920210dec16302"
|
||||
|
||||
ua, err := Uint160DecodeString(a)
|
||||
ua, err := Uint160DecodeStringBE(a)
|
||||
require.NoError(t, err)
|
||||
|
||||
ub, err := Uint160DecodeString(b)
|
||||
ub, err := Uint160DecodeStringBE(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)
|
||||
|
@ -73,11 +90,11 @@ func TestUInt160Less(t *testing.T) {
|
|||
a := "2d3b96ae1bcc5a585e075e3b81920210dec16302"
|
||||
b := "2d3b96ae1bcc5a585e075e3b81920210dec16303"
|
||||
|
||||
ua, err := Uint160DecodeString(a)
|
||||
ua, err := Uint160DecodeStringBE(a)
|
||||
assert.Nil(t, err)
|
||||
ua2, err := Uint160DecodeString(a)
|
||||
ua2, err := Uint160DecodeStringBE(a)
|
||||
assert.Nil(t, err)
|
||||
ub, err := Uint160DecodeString(b)
|
||||
ub, err := Uint160DecodeStringBE(b)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, true, ua.Less(ub))
|
||||
assert.Equal(t, false, ua.Less(ua2))
|
||||
|
@ -88,9 +105,18 @@ func TestUInt160String(t *testing.T) {
|
|||
hexStr := "b28427088a3729b2536d10122960394e8be6721f"
|
||||
hexRevStr := "1f72e68b4e39602912106d53b229378a082784b2"
|
||||
|
||||
val, err := Uint160DecodeString(hexStr)
|
||||
val, err := Uint160DecodeStringBE(hexStr)
|
||||
assert.Nil(t, err)
|
||||
|
||||
assert.Equal(t, hexStr, val.String())
|
||||
assert.Equal(t, hexRevStr, val.ReverseString())
|
||||
assert.Equal(t, hexRevStr, val.StringLE())
|
||||
}
|
||||
|
||||
func TestUint160_Reverse(t *testing.T) {
|
||||
hexStr := "b28427088a3729b2536d10122960394e8be6721f"
|
||||
val, err := Uint160DecodeStringBE(hexStr)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, hexStr, val.Reverse().StringLE())
|
||||
assert.Equal(t, val, val.Reverse().Reverse())
|
||||
}
|
||||
|
|
|
@ -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,26 @@ 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) {
|
||||
// Uint256DecodeStringBE attempts to decode the given string (in BE representation)
|
||||
// into an Uint256.
|
||||
func Uint256DecodeStringBE(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))
|
||||
}
|
||||
|
||||
b, err := hex.DecodeString(s)
|
||||
if err != nil {
|
||||
return u, err
|
||||
}
|
||||
|
||||
return Uint256DecodeBytesBE(b)
|
||||
}
|
||||
|
||||
// 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 +52,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 +81,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 +101,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,33 @@ 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())
|
||||
|
||||
valBE, err := Uint256DecodeStringBE(hexStr)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, val, valBE.Reverse())
|
||||
|
||||
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)
|
||||
|
||||
_, err = Uint256DecodeStringBE(hexStr[1:])
|
||||
assert.Error(t, err)
|
||||
|
||||
hexStr = "zzz7308fa0ab18155bccfc08485468c112409ea5064595699e98c545f245f32d"
|
||||
_, err = Uint256DecodeReverseString(hexStr)
|
||||
_, err = Uint256DecodeStringLE(hexStr)
|
||||
assert.Error(t, err)
|
||||
|
||||
_, err = Uint256DecodeStringBE(hexStr)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
|
@ -58,11 +68,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 +80,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)
|
||||
|
|
|
@ -118,7 +118,7 @@ func EmitAppCall(w *bytes.Buffer, scriptHash util.Uint160, tailCall bool) error
|
|||
if tailCall {
|
||||
op = opcode.TAILCALL
|
||||
}
|
||||
return Emit(w, op, scriptHash.Bytes())
|
||||
return Emit(w, op, scriptHash.BytesBE())
|
||||
}
|
||||
|
||||
// EmitAppCallWithOperationAndData emits an appcall with the given operation and data.
|
||||
|
|
12
pkg/vm/vm.go
12
pkg/vm/vm.go
|
@ -1112,7 +1112,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
|||
v.checkInvocationStackSize()
|
||||
}
|
||||
|
||||
hash, err := util.Uint160DecodeBytes(parameter)
|
||||
hash, err := util.Uint160DecodeBytesBE(parameter)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -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,15 +1292,15 @@ 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()
|
||||
v.estack.PushVal(hash.Hash160(b).Bytes())
|
||||
v.estack.PushVal(hash.Hash160(b).BytesBE())
|
||||
|
||||
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 ^^
|
||||
|
@ -1341,7 +1341,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
|||
hashBytes = parameter[2:]
|
||||
}
|
||||
|
||||
hash, err := util.Uint160DecodeBytes(hashBytes)
|
||||
hash, err := util.Uint160DecodeBytesBE(hashBytes)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -1403,7 +1403,7 @@ func TestSIGNByteArray(t *testing.T) {
|
|||
func TestAppCall(t *testing.T) {
|
||||
prog := []byte{byte(opcode.APPCALL)}
|
||||
hash := util.Uint160{}
|
||||
prog = append(prog, hash.Bytes()...)
|
||||
prog = append(prog, hash.BytesBE()...)
|
||||
prog = append(prog, byte(opcode.RET))
|
||||
|
||||
vm := load(prog)
|
||||
|
@ -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