Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Zhang committed May 27, 2017
1 parent 80affc4 commit fdafe69
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/AntShares/AntShares.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Copyright>2015-2017 The Antshares team</Copyright>
<AssemblyTitle>AntShares</AssemblyTitle>
<VersionPrefix>1.6.1</VersionPrefix>
<Version>1.6.2</Version>
<Authors>The Antshares team</Authors>
<TargetFrameworks>netstandard1.6;net461</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
2 changes: 2 additions & 0 deletions src/AntShares/Core/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ byte[] IScriptTable.GetScript(byte[] script_hash)
return GetContract(new UInt160(script_hash)).Code.Script;
}

public abstract StorageItem GetStorageItem(StorageKey key);

/// <summary>
/// 根据指定的区块高度,返回对应区块及之前所有区块中包含的系统费用的总量
/// </summary>
Expand Down
4 changes: 0 additions & 4 deletions src/AntShares/Core/TransactionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ public enum TransactionType : byte
/// </summary>
ContractTransaction = 0x80,
/// <summary>
/// 委托交易
/// </summary>
AgencyTransaction = 0xb0,
/// <summary>
/// Publish scripts to the blockchain for being invoked later.
/// </summary>
PublishTransaction = 0xd0,
Expand Down
4 changes: 2 additions & 2 deletions src/AntShares/IO/Caching/DataCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public abstract class DataCache<TKey, TValue>
where TKey : IEquatable<TKey>, ISerializable
where TValue : class, ISerializable, new()
{
protected class Trackable
protected internal class Trackable
{
public TKey Key;
public TValue Item;
Expand Down Expand Up @@ -73,7 +73,7 @@ public void DeleteWhere(Func<TKey, TValue, bool> predicate)
trackable.State = TrackState.Deleted;
}

protected IEnumerable<Trackable> GetChangeSet()
protected internal IEnumerable<Trackable> GetChangeSet()
{
return dictionary.Values.Where(p => p.State != TrackState.None);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using AntShares.Cryptography;
using AntShares.Cryptography.ECC;
using AntShares.IO;
using AntShares.IO.Caching;
using AntShares.SmartContract;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -274,6 +275,11 @@ public override UInt256 GetNextBlockHash(UInt256 hash)
}
}

public override StorageItem GetStorageItem(StorageKey key)
{
return db.TryGet<StorageItem>(ReadOptions.Default, DataEntryPrefix.ST_Storage, key);
}

public override long GetSysFeeAmount(UInt256 hash)
{
Slice value;
Expand Down Expand Up @@ -547,8 +553,14 @@ private void Persist(Block block)
spentcoins.Commit(batch);
validators.Commit(batch);
assets.Commit(batch);
HashSet<UInt160> contracts_deleted = new HashSet<UInt160>(contracts.GetChangeSet().Where(p => p.State == TrackState.Deleted).Select(p => p.Key));
contracts.Commit(batch);
if (contracts_deleted.Count > 0)
storages.DeleteWhere((k, v) => contracts_deleted.Contains(k.ScriptHash));
storages.Commit(batch);
foreach (UInt160 script_hash in contracts_deleted)
foreach (Slice key in db.Find(ReadOptions.Default, SliceBuilder.Begin(DataEntryPrefix.ST_Storage).Add(script_hash), (k, v) => k))
batch.Delete(key);
batch.Put(SliceBuilder.Begin(DataEntryPrefix.SYS_CurrentBlock), SliceBuilder.Begin().Add(block.Hash).Add(block.Index));
db.Write(WriteOptions.Default, batch);
current_block_height = block.Index;
Expand Down
17 changes: 17 additions & 0 deletions src/AntShares/Network/RPC/RpcServer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AntShares.Core;
using AntShares.IO;
using AntShares.IO.Json;
using AntShares.Wallets;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -140,6 +141,22 @@ protected virtual JObject Process(string method, JArray _params)
Block block = _params[0].AsString().HexToBytes().AsSerializable<Block>();
return LocalNode.Relay(block);
}
case "validateaddress":
{
JObject json = new JObject();
UInt160 scriptHash;
try
{
scriptHash = Wallet.ToScriptHash(_params[0].AsString());
}
catch
{
scriptHash = null;
}
json["address"] = _params[0];
json["isvalid"] = scriptHash != null;
return json;
}
default:
throw new RpcException(-32601, "Method not found");
}
Expand Down
9 changes: 9 additions & 0 deletions src/AntShares/SmartContract/StateMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ protected override bool Blockchain_GetAccount(ExecutionEngine engine)
return true;
}

protected override bool Blockchain_GetAsset(ExecutionEngine engine)
{
UInt256 hash = new UInt256(engine.EvaluationStack.Pop().GetByteArray());
AssetState asset = assets.TryGet(hash);
if (asset == null) return false;
engine.EvaluationStack.Push(StackItem.FromInterface(asset));
return true;
}

private bool Account_SetVotes(ExecutionEngine engine)
{
AccountState account = engine.EvaluationStack.Pop().GetInterface<AccountState>();
Expand Down

0 comments on commit fdafe69

Please sign in to comment.