Skip to content

Commit

Permalink
split script from transaction attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Zhang committed Nov 10, 2016
1 parent 469df0f commit bca5be5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
7 changes: 1 addition & 6 deletions src/AntShares/Core/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ public virtual UInt160[] GetScriptHashesForVerifying()
{
if (References == null) throw new InvalidOperationException();
HashSet<UInt160> hashes = new HashSet<UInt160>(Inputs.Select(p => References[p].ScriptHash));
hashes.UnionWith(Attributes.Where(p => p.Usage == TransactionAttributeUsage.Script).Select(p => new UInt160(p.Data)));
foreach (var group in Outputs.GroupBy(p => p.AssetId))
{
RegisterTransaction tx = Blockchain.Default.GetTransaction(group.Key) as RegisterTransaction;
Expand Down Expand Up @@ -358,12 +359,6 @@ public virtual bool Verify()
return false;
break;
}
foreach (TransactionAttribute script in Attributes.Where(p => p.Usage == TransactionAttributeUsage.Script))
{
ScriptEngine engine = new ScriptEngine(this, ECDsaCrypto.Default, Blockchain.Default, InterfaceEngine.Default);
if (!engine.ExecuteScript(script.Data, false)) return false;
if (engine.Stack.Count != 1 || !engine.Stack.Pop()) return false;
}
if (Attributes.Any(p => p.Usage == TransactionAttributeUsage.Vote))
{
if (!Blockchain.Default.Ability.HasFlag(BlockchainAbility.UnspentIndexes))
Expand Down
8 changes: 4 additions & 4 deletions src/AntShares/Core/TransactionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public int Size
{
if (Usage == TransactionAttributeUsage.ContractHash || Usage == TransactionAttributeUsage.ECDH02 || Usage == TransactionAttributeUsage.ECDH03 || Usage == TransactionAttributeUsage.Vote || (Usage >= TransactionAttributeUsage.Hash1 && Usage <= TransactionAttributeUsage.Hash15))
return sizeof(TransactionAttributeUsage) + 32;
else if (Usage == TransactionAttributeUsage.Script)
return sizeof(TransactionAttributeUsage) + 20;
else if (Usage == TransactionAttributeUsage.CertUrl || Usage == TransactionAttributeUsage.DescriptionUrl)
return sizeof(TransactionAttributeUsage) + sizeof(byte) + Data.Length;
else
Expand All @@ -42,7 +44,7 @@ void ISerializable.Deserialize(BinaryReader reader)
else if (Usage == TransactionAttributeUsage.ECDH02 || Usage == TransactionAttributeUsage.ECDH03)
Data = new[] { (byte)Usage }.Concat(reader.ReadBytes(32)).ToArray();
else if (Usage == TransactionAttributeUsage.Script)
Data = reader.ReadVarBytes(ushort.MaxValue);
Data = reader.ReadBytes(20);
else if (Usage == TransactionAttributeUsage.CertUrl || Usage == TransactionAttributeUsage.DescriptionUrl)
Data = reader.ReadBytes(reader.ReadByte());
else if (Usage == TransactionAttributeUsage.Description || Usage >= TransactionAttributeUsage.Remark)
Expand All @@ -54,9 +56,7 @@ void ISerializable.Deserialize(BinaryReader reader)
void ISerializable.Serialize(BinaryWriter writer)
{
writer.Write((byte)Usage);
if (Usage == TransactionAttributeUsage.Script)
writer.WriteVarInt(Data.Length);
else if (Usage == TransactionAttributeUsage.CertUrl || Usage == TransactionAttributeUsage.DescriptionUrl)
if (Usage == TransactionAttributeUsage.CertUrl || Usage == TransactionAttributeUsage.DescriptionUrl)
writer.Write((byte)Data.Length);
else if (Usage == TransactionAttributeUsage.Description || Usage >= TransactionAttributeUsage.Remark)
writer.WriteVarInt(Data.Length);
Expand Down

0 comments on commit bca5be5

Please sign in to comment.