Skip to content

Commit

Permalink
upgrade to AntShares.VM 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Zhang committed Mar 23, 2017
1 parent 6000cb5 commit adafcea
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/AntShares/Core/BlockBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void ISignable.SerializeUnsigned(BinaryWriter writer)
writer.Write(NextMiner);
}

byte[] IApiInterface.ToArray()
byte[] IInteropInterface.ToArray()
{
return this.ToArray();
}
Expand Down
8 changes: 4 additions & 4 deletions src/AntShares/Core/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public abstract class Blockchain : IDisposable, IScriptTable
Amount = Fixed8.FromDecimal(100000000),
Precision = 0,
Issuer = ECCurve.Secp256r1.Infinity,
Admin = (new[] { (byte)OpCode.OP_TRUE }).ToScriptHash(),
Admin = (new[] { (byte)OpCode.PUSHT }).ToScriptHash(),
Attributes = new TransactionAttribute[0],
Inputs = new CoinReference[0],
Outputs = new TransactionOutput[0]
Expand All @@ -67,7 +67,7 @@ public abstract class Blockchain : IDisposable, IScriptTable
Amount = Fixed8.FromDecimal(MintingAmount.Sum(p => p * DecrementInterval)),
Precision = 8,
Issuer = ECCurve.Secp256r1.Infinity,
Admin = (new[] { (byte)OpCode.OP_FALSE }).ToScriptHash(),
Admin = (new[] { (byte)OpCode.PUSHF }).ToScriptHash(),
Attributes = new TransactionAttribute[0],
Inputs = new CoinReference[0],
Outputs = new TransactionOutput[0]
Expand All @@ -86,7 +86,7 @@ public abstract class Blockchain : IDisposable, IScriptTable
Script = new Witness
{
StackScript = new byte[0],
RedeemScript = new[] { (byte)OpCode.OP_TRUE }
RedeemScript = new[] { (byte)OpCode.PUSHT }
},
Transactions = new Transaction[]
{
Expand Down Expand Up @@ -118,7 +118,7 @@ public abstract class Blockchain : IDisposable, IScriptTable
new Witness
{
StackScript = new byte[0],
RedeemScript = new[] { (byte)OpCode.OP_TRUE }
RedeemScript = new[] { (byte)OpCode.PUSHT }
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/AntShares/Core/CoinReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace AntShares.Core
/// <summary>
/// 交易输入
/// </summary>
public class CoinReference : IApiInterface, IEquatable<CoinReference>, ISerializable
public class CoinReference : IEquatable<CoinReference>, IInteropInterface, ISerializable
{
/// <summary>
/// 引用交易的散列值
Expand Down Expand Up @@ -68,7 +68,7 @@ void ISerializable.Serialize(BinaryWriter writer)
writer.Write(PrevIndex);
}

byte[] IApiInterface.ToArray()
byte[] IInteropInterface.ToArray()
{
return this.ToArray();
}
Expand Down
2 changes: 1 addition & 1 deletion src/AntShares/Core/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ internal static bool VerifySignature(this ISignable signable)
engine.LoadScript(signable.Scripts[i].StackScript, true);
engine.Execute();
if (engine.State != VMState.HALT) return false;
if (engine.EvaluationStack.Count != 1 || !engine.EvaluationStack.Pop()) return false;
if (engine.EvaluationStack.Count != 1 || !engine.EvaluationStack.Pop().GetBoolean()) return false;
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/AntShares/Core/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ void ISignable.SerializeUnsigned(BinaryWriter writer)
writer.Write(Outputs);
}

byte[] IApiInterface.ToArray()
byte[] IInteropInterface.ToArray()
{
return this.ToArray();
}
Expand Down
4 changes: 2 additions & 2 deletions src/AntShares/Core/TransactionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace AntShares.Core
/// <summary>
/// 交易特性
/// </summary>
public class TransactionAttribute : IApiInterface, ISerializable
public class TransactionAttribute : IInteropInterface, ISerializable
{
/// <summary>
/// 用途
Expand Down Expand Up @@ -66,7 +66,7 @@ void ISerializable.Serialize(BinaryWriter writer)
writer.Write(Data);
}

byte[] IApiInterface.ToArray()
byte[] IInteropInterface.ToArray()
{
return this.ToArray();
}
Expand Down
4 changes: 2 additions & 2 deletions src/AntShares/Core/TransactionOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace AntShares.Core
/// <summary>
/// 交易输出
/// </summary>
public class TransactionOutput : IApiInterface, ISerializable
public class TransactionOutput : IInteropInterface, ISerializable
{
/// <summary>
/// 资产编号
Expand Down Expand Up @@ -42,7 +42,7 @@ void ISerializable.Serialize(BinaryWriter writer)
writer.Write(ScriptHash);
}

byte[] IApiInterface.ToArray()
byte[] IInteropInterface.ToArray()
{
return this.ToArray();
}
Expand Down
2 changes: 1 addition & 1 deletion src/AntShares/Network/Payloads/ConsensusPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void ISignable.SerializeUnsigned(BinaryWriter writer)
writer.WriteVarBytes(Data);
}

byte[] IApiInterface.ToArray()
byte[] IInteropInterface.ToArray()
{
return this.ToArray();
}
Expand Down
40 changes: 15 additions & 25 deletions src/AntShares/VM/InterfaceEngine.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using AntShares.Core;
using System.Numerics;
using System.Linq;

namespace AntShares.VM
{
internal class InterfaceEngine : ApiService
internal class InterfaceEngine : InteropService
{
public static readonly InterfaceEngine Default = new InterfaceEngine();

Expand Down Expand Up @@ -54,7 +54,7 @@ private static bool Blockchain_GetHeight(ExecutionEngine engine)

private static bool Blockchain_GetHeader(ExecutionEngine engine)
{
byte[] data = (byte[])engine.EvaluationStack.Pop();
byte[] data = engine.EvaluationStack.Pop().GetByteArray();
Header header;
switch (data.Length)
{
Expand All @@ -79,13 +79,13 @@ private static bool Blockchain_GetHeader(ExecutionEngine engine)
default:
return false;
}
engine.EvaluationStack.Push(new StackItem(header));
engine.EvaluationStack.Push(StackItem.FromInterface(header));
return true;
}

private static bool Blockchain_GetBlock(ExecutionEngine engine)
{
byte[] data = (byte[])engine.EvaluationStack.Pop();
byte[] data = engine.EvaluationStack.Pop().GetByteArray();
Block block;
switch (data.Length)
{
Expand All @@ -110,15 +110,15 @@ private static bool Blockchain_GetBlock(ExecutionEngine engine)
default:
return false;
}
engine.EvaluationStack.Push(new StackItem(block));
engine.EvaluationStack.Push(StackItem.FromInterface(block));
return true;
}

private static bool Blockchain_GetTransaction(ExecutionEngine engine)
{
byte[] hash = (byte[])engine.EvaluationStack.Pop();
byte[] hash = engine.EvaluationStack.Pop().GetByteArray();
Transaction tx = Blockchain.Default?.GetTransaction(new UInt256(hash));
engine.EvaluationStack.Push(new StackItem(tx));
engine.EvaluationStack.Push(StackItem.FromInterface(tx));
return true;
}

Expand Down Expand Up @@ -190,20 +190,18 @@ private static bool Block_GetTransactions(ExecutionEngine engine)
{
Block block = engine.EvaluationStack.Pop().GetInterface<Block>();
if (block == null) return false;
for (int i = block.Transactions.Length - 1; i >= 0; i--)
engine.EvaluationStack.Push(new StackItem(block.Transactions[i]));
engine.EvaluationStack.Push(block.Transactions.Length);
engine.EvaluationStack.Push(block.Transactions.Select(p => StackItem.FromInterface(p)).ToArray());
return true;
}

private static bool Block_GetTransaction(ExecutionEngine engine)
{
int index = (int)(BigInteger)engine.EvaluationStack.Pop();
Block block = engine.EvaluationStack.Pop().GetInterface<Block>();
int index = (int)engine.EvaluationStack.Pop().GetBigInteger();
if (block == null) return false;
if (index < 0 || index >= block.Transactions.Length) return false;
Transaction tx = block.Transactions[index];
engine.EvaluationStack.Push(new StackItem(tx));
engine.EvaluationStack.Push(StackItem.FromInterface(tx));
return true;
}

Expand Down Expand Up @@ -267,39 +265,31 @@ private static bool Transaction_GetAttributes(ExecutionEngine engine)
{
Transaction tx = engine.EvaluationStack.Pop().GetInterface<Transaction>();
if (tx == null) return false;
for (int i = tx.Attributes.Length - 1; i >= 0; i--)
engine.EvaluationStack.Push(new StackItem(tx.Attributes[i]));
engine.EvaluationStack.Push(tx.Attributes.Length);
engine.EvaluationStack.Push(tx.Attributes.Select(p => StackItem.FromInterface(p)).ToArray());
return true;
}

private static bool Transaction_GetInputs(ExecutionEngine engine)
{
Transaction tx = engine.EvaluationStack.Pop().GetInterface<Transaction>();
if (tx == null) return false;
for (int i = tx.Inputs.Length - 1; i >= 0; i--)
engine.EvaluationStack.Push(new StackItem(tx.Inputs[i]));
engine.EvaluationStack.Push(tx.Inputs.Length);
engine.EvaluationStack.Push(tx.Inputs.Select(p => StackItem.FromInterface(p)).ToArray());
return true;
}

private static bool Transaction_GetOutputs(ExecutionEngine engine)
{
Transaction tx = engine.EvaluationStack.Pop().GetInterface<Transaction>();
if (tx == null) return false;
for (int i = tx.Outputs.Length - 1; i >= 0; i--)
engine.EvaluationStack.Push(new StackItem(tx.Outputs[i]));
engine.EvaluationStack.Push(tx.Outputs.Length);
engine.EvaluationStack.Push(tx.Outputs.Select(p => StackItem.FromInterface(p)).ToArray());
return true;
}

private static bool Transaction_GetReferences(ExecutionEngine engine)
{
Transaction tx = engine.EvaluationStack.Pop().GetInterface<Transaction>();
if (tx == null) return false;
for (int i = tx.Inputs.Length - 1; i >= 0; i--)
engine.EvaluationStack.Push(new StackItem(tx.References[tx.Inputs[i]]));
engine.EvaluationStack.Push(tx.Inputs.Length);
engine.EvaluationStack.Push(tx.Inputs.Select(p => StackItem.FromInterface(tx.References[p])).ToArray());
return true;
}

Expand Down
12 changes: 6 additions & 6 deletions src/AntShares/Wallets/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public bool IsStandard
get
{
if (Script.Length != 35) return false;
if (Script[0] != 33 || Script[34] != (byte)OpCode.OP_CHECKSIG)
if (Script[0] != 33 || Script[34] != (byte)OpCode.CHECKSIG)
return false;
return true;
}
Expand Down Expand Up @@ -87,7 +87,7 @@ public static byte[] CreateMultiSigRedeemScript(int m, params ECPoint[] publicKe
sb.EmitPush(publicKey.EncodePoint(true));
}
sb.EmitPush(publicKeys.Length);
sb.Emit(OpCode.OP_CHECKMULTISIG);
sb.Emit(OpCode.CHECKMULTISIG);
return sb.ToArray();
}
}
Expand All @@ -107,7 +107,7 @@ public static byte[] CreateSignatureRedeemScript(ECPoint publicKey)
using (ScriptBuilder sb = new ScriptBuilder())
{
sb.EmitPush(publicKey.EncodePoint(true));
sb.Emit(OpCode.OP_CHECKSIG);
sb.Emit(OpCode.CHECKSIG);
return sb.ToArray();
}
}
Expand Down Expand Up @@ -159,8 +159,8 @@ private bool IsMultiSigContract()
int m, n = 0;
int i = 0;
if (Script.Length < 37) return false;
if (Script[i] > (byte)OpCode.OP_16) return false;
if (Script[i] < (byte)OpCode.OP_1 && Script[i] != 1 && Script[i] != 2) return false;
if (Script[i] > (byte)OpCode.PUSH16) return false;
if (Script[i] < (byte)OpCode.PUSH1 && Script[i] != 1 && Script[i] != 2) return false;
switch (Script[i])
{
case 1:
Expand Down Expand Up @@ -197,7 +197,7 @@ private bool IsMultiSigContract()
if (n != Script[i++] - 80) return false;
break;
}
if (Script[i++] != (byte)OpCode.OP_CHECKMULTISIG) return false;
if (Script[i++] != (byte)OpCode.CHECKMULTISIG) return false;
if (Script.Length != i) return false;
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/AntShares/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"authors": [ "The Antshares team" ],
"copyright": "2015-2016 The Antshares team",
"title": "AntShares",
"version": "1.4.5",
"version": "1.4.6",
"buildOptions": {
"allowUnsafe": true,
"copyToOutput": {
Expand All @@ -27,8 +27,8 @@
},

"dependencies": {
"AntShares.Compiler": "1.4.0",
"AntShares.VM": "1.4.0",
"AntShares.Compiler": "1.5.0",
"AntShares.VM": "1.5.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.1",
"Microsoft.EntityFrameworkCore.Sqlite": "1.0.0",
Expand Down

0 comments on commit adafcea

Please sign in to comment.