Skip to content

Commit

Permalink
Merge pull request #127 from Ashuaidehao/dev-back
Browse files Browse the repository at this point in the history
fix opcode
  • Loading branch information
Ashuaidehao authored Aug 6, 2021
2 parents 318c42f + 7d468ee commit c45fd47
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 56 deletions.
33 changes: 33 additions & 0 deletions neo3-gui/neo3-gui.tests/OpCodeParser_Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo;
using Neo.Common.Utility;
using Neo.VM;

namespace neo3_gui.tests
{
[TestClass]
public class OpCodeParser_Test
{
[TestMethod]
public void Test()
{

var script =
"0d4501e70f75f78a0bc128ea55c53bffec7f0d2fa4da5793e5c810d3faf78bcf0f517a73d98e5911db9d13bfeaa69a4ab84a356241aa11e23b970be6cf2fe06aeb1cc60108d7699fe00e9ae224bfeca82e49af360d30ff80edf972ad2d323461e82778af33453db04a34275cfbbe2af1eb692eece921b16a4b18a16a1d8ce850baab32ef01e041b3b53218b755a58cc84a938de52e648f00e010ee1ea87f0a0eb12af9d7427fc477dbf566e0fca084017ec2bae5e1a1bbb9539c59170cf687e45a8ddeba0e01feb56c064339cc468d3ade9179754887579f04b612c4c2cc5c1d8f6c0781246071f68900248c6b56724135428600988f0b850d5464d59206f820a9590445663a01449d1a8b4e08ed8e06ee250d57a701f390aed87dcb75456d112661035733b1944fc5f66f5c417041ab7180134f2ef1729f714bd02de35d3bef10f554843dad2d000c000c000dc60100000000ffffffffffffff7fdef0100970c3cb67e2c8066a6a97d3c1669d03fc91045bbe1b84eec97b0ad08932824d90bd7c27c90a413483c3635b59f3d3a040e1ab74485c99614e835e2bd02bda7e1ab674e41ac8254b11fb06361b70d57591551da475c7ffc7e3f3ce6dde3fd1ad4bca7e978ada9f9154365f63c855f468a19c8ad3e59d4778c531d4b0c6113bf9607778b900067b3c67a0fb82dbfd13017b226c6561646572223a352c227672665f76616c7565223a22424c6769682f62574378672b54617a5a326253496a556354586e2f2f754679575a6e5876377953774467744a474e377a4d7974442f7637424341536a634f676b7754656d414c68786e636458566252335a75324e4952673d222c227672665f70726f6f66223a2266465074723936425a735461514269766c43693370715a47696241496832384c534d506f4f6b6a4f4b7376686475447a30324e7861753659313171686874384f514e7751323347787a58513638694239774b334f76673d3d222c226c6173745f636f6e6669675f626c6f636b5f6e756d223a31323135303736372c226e65775f636861696e5f636f6e666967223a6e756c6c7d00000000000000000000000000000000000000000cf0ef20702f6edd397bf6181e391867ba23ec77d2ad717748ab8d914d9ec1e5db74afa605000000000000002064c809ee29044d8cd6ad05dce818c5d8000ed816d0e74c04fb97c5246d29356420fd03f64d5c82a6123d30528507c709e14bda44f4ab3d8ff399c5d5f4d90cd8d2144f5f702b3f459f222d371052940bb9ce2d86d2ed58000000000000001442e54382e86dcdca09e0da8bb67e2fac4d49874406756e6c6f636b4a14cf76e28bd0062c4a478ee35561011319f3cfa4d2140482c3d160c011bf95d2b7ed3b5da7688181ce67009c9f060000000000000000000000000000000000000000000000000000000015c01f0c12766572696679416e644578656375746554780c142a774fa0404f020254f6db20616cf13adc448d6141627d5b52"
.HexToBytes();


var instructions = OpCodeConverter.Parse(script);
foreach (var instructionInfo in instructions)
{
Console.WriteLine($"My:{instructionInfo.OpCode},{instructionInfo.OpData?.ToHexString()}");

}
}
}
}
13 changes: 0 additions & 13 deletions neo3-gui/neo3-gui.tests/TestBlockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,5 @@ public static class TestBlockchain
{
public static readonly NeoSystem TheNeoSystem;

static TestBlockchain()
{
Console.WriteLine("initialize NeoSystem");
TheNeoSystem = new NeoSystem();

// Ensure that blockchain is loaded

var _ = Blockchain.Singleton;
}

public static void InitializeMockNeoSystem()
{
}
}
}
12 changes: 7 additions & 5 deletions neo3-gui/neo3-gui/ClientApp/src/components/Contract/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ class ContractUpgrade extends React.Component {
selectNef = async () => {
this.opendialog("nef", async (res) => {
let nef = res.filePaths[0];
let manifest = nef.substring(0, nef.length - 3) + "manifest.json";
if (fs.existsSync(manifest)) {
await this.setState({ manipath: manifest });
if (nef) {
let manifest = nef.substring(0, nef.length - 3) + "manifest.json";
if (fs.existsSync(manifest)) {
await this.setState({ manipath: manifest });
}
await this.setState({ nefpath: nef, isOpenDialog: false });
this.onFill()
}
await this.setState({ nefpath: nef, isOpenDialog: false });
this.onFill()
});
};
selectMani = async () => {
Expand Down
57 changes: 20 additions & 37 deletions neo3-gui/neo3-gui/Common/Utility/OpCodeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,50 +42,33 @@ public static string ToAsciiString(byte[] byteArray)
public static List<InstructionInfo> Parse(byte[] scripts)
{
var result = new List<InstructionInfo>();
var position = 0;
while (position < scripts.Length)
try
{
var instruction = new InstructionInfo() { Position = position };
var op = scripts[position++];
instruction.OpCode = (OpCode)op;
var operandSizePrefix = _operandSizePrefixTable[op];
var operandSize = 0;
switch (operandSizePrefix)
var s = new Script(scripts);
for (int ip = 0; ip < scripts.Length;)
{
case 0:
operandSize = _operandSizeTable[op];
break;
case 1:
operandSize = scripts[position];
break;
case 2:
operandSize = BitConverter.ToUInt16(scripts, position);
break;
case 4:
operandSize = BitConverter.ToInt32(scripts, position);
break;
}
if (operandSize > 0)
{
position += operandSizePrefix;
if (position + operandSize > scripts.Length)
{
//warning
instruction.OpData= new ReadOnlyMemory<byte>(scripts, position,scripts.Length-position).ToArray();
result.Add(instruction);
return result;
//throw new InvalidOperationException();
}
instruction.OpData = new ReadOnlyMemory<byte>(scripts, position, operandSize).ToArray();
var instruction = s.GetInstruction(ip);

var instructionInfo = new InstructionInfo()
{OpCode = instruction.OpCode, Position = ip, OpData = instruction.Operand.ToArray()};

if (instruction.OpCode == OpCode.SYSCALL)
{
instruction.SystemCallMethod = _interopServiceMap[BitConverter.ToUInt32(instruction.OpData)];
instructionInfo.SystemCallMethod = _interopServiceMap[BitConverter.ToUInt32(instructionInfo.OpData)];
}


result.Add(instructionInfo);


ip += instruction.Size;
}
result.Add(instruction);
position += operandSize;

}
catch (Exception e)
{
Console.WriteLine($"{scripts.ToHexString()}:{e}");
}

return result;
}

Expand Down
2 changes: 1 addition & 1 deletion neo3-gui/neo3-gui/config.testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"Storage": {
"Engine": "LevelDBStore",
"Path": "Data_LevelDB_877933390"
"Path": "Data_LevelDB_TestNet"
},
"P2P": {
"Port": 20333,
Expand Down

0 comments on commit c45fd47

Please sign in to comment.