Skip to content

Commit

Permalink
Merge pull request #42 from loning/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
loning authored Feb 2, 2018
2 parents 9533f1c + 3a0b505 commit 826dabc
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 92 deletions.
17 changes: 2 additions & 15 deletions AElf.Kernel/Chain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,8 @@ public class Chain : IChain
/// <value>The blocks.</value>
public List<Block> Blocks { get; set; } = new List<Block>();

public long CurrentBlockHeight
{
get
{
return Blocks.Count;
}
}

public IHash<IBlock> CurrentBlockHash
{
get
{
return new Hash<IBlock>(Blocks[Blocks.Count - 1].GetHeader().GetTransactionMerkleTreeRoot().Value);
}
}
public long CurrentBlockHeight => Blocks.Count;

public IHash<IBlock> CurrentBlockHash => new Hash<IBlock>(Blocks[Blocks.Count - 1].GetHeader().GetTransactionMerkleTreeRoot().Value);
}
}
4 changes: 2 additions & 2 deletions AElf.Kernel/ChainManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ChainManager : IChainManager
public Task AddBlockAsync(IChain chain, IBlock block)
{
return new Task(() =>(chain as Chain).Blocks.Add(block as Block));

}
}

}
}
2 changes: 0 additions & 2 deletions AElf.Kernel/IAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ public interface IAccount
/// </summary>
/// <returns></returns>
IHash<IAccount> GetAddress();

ISmartContractInvoker CreateInvoker(string methodName, params object[] values);
}
}
7 changes: 7 additions & 0 deletions AElf.Kernel/IAccountDataContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace AElf.Kernel
{
public interface IAccountDataContext
{
ulong IncreasementId { get; set; }
}
}
27 changes: 5 additions & 22 deletions AElf.Kernel/IAccountDataProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace AElf.Kernel
{
Expand All @@ -7,29 +8,11 @@ namespace AElf.Kernel
/// </summary>
public interface IAccountDataProvider
{
/// <summary>
/// Gets the data merkle tree root.
/// </summary>
/// <returns></returns>
Task<IHash<IMerkleTree<ISerializable>>> GetDataMerkleTreeRootAsync();

/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
Task<ISerializable> GetAsync(IHash key);

/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="obj"></param>
/// <returns></returns>
Task SetAsync(IHash key,ISerializable obj);

IAccountDataContext Context { get; set; }

IHash<IAccount> GetAccountAddress();

Task<IAccountDataProvider> GetMapAsync(string name);
IDataProvider GetDataProvider();
}
}
32 changes: 32 additions & 0 deletions AElf.Kernel/IDataProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Threading.Tasks;

namespace AElf.Kernel
{
public interface IDataProvider
{
IDataProvider GetDataProvider(string name);


/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
Task<ISerializable> GetAsync(IHash key);

/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="obj"></param>
/// <returns></returns>
Task SetAsync(IHash key,ISerializable obj);

/// <summary>
/// Gets the data merkle tree root.
/// </summary>
/// <returns></returns>
Task<IHash<IMerkleTree<ISerializable>>> GetDataMerkleTreeRootAsync();

}
}
14 changes: 14 additions & 0 deletions AElf.Kernel/ISmartContract.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace AElf.Kernel
{

public interface ISmartContract
{
Task InititalizeAsync(IAccountDataProvider dataProvider);
Task InvokeAsync(IHash<IAccount> caller,
string methodname, params object[] objs);
}

}
9 changes: 0 additions & 9 deletions AElf.Kernel/ISmartContractInvoker.cs

This file was deleted.

9 changes: 9 additions & 0 deletions AElf.Kernel/ISmartContractManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;

namespace AElf.Kernel
{
public interface ISmartContractManager
{
Task<ISmartContract> GetAsync(IAccount account);
}
}
1 change: 1 addition & 0 deletions AElf.Kernel/ITransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ public interface ITransaction

ulong IncrementId { get; set; }
}

}
5 changes: 0 additions & 5 deletions AElf.Kernel/KernelAccount/AccountZero.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,5 @@ public IHash<IAccount> GetAddress()
{
return Hash<IAccount>.Zero;
}

public ISmartContractInvoker CreateInvoker(string methodName, params object[] values)
{
throw new NotImplementedException();
}
}
}
27 changes: 0 additions & 27 deletions AElf.Kernel/KernelAccount/SmartContractInvokerZero.cs

This file was deleted.

10 changes: 6 additions & 4 deletions AElf.Kernel/KernelAccount/SmartContractZero.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace AElf.Kernel.KernelAccount
{
public class SmartContractZero
public class SmartContractZero: ISmartContract
{
private const string SMART_CONTRACT_MAP_KEY = "SmartContractMap";

private IAccountDataProvider _accountDataProvider;

public async void InititalizeAsync(IAccountDataProvider dataProvider)
public async Task InititalizeAsync(IAccountDataProvider dataProvider)
{
_accountDataProvider = dataProvider;
await Task.CompletedTask;
}

public async Task InvokeAsync(IHash<IAccount> caller, string methodname, params object[] objs)
Expand All @@ -24,7 +26,7 @@ public async Task InvokeAsync(IHash<IAccount> caller, string methodname, params
// Hard coded method in the kernel
public async Task RegisterSmartContract(SmartContractRegistration reg)
{
var smartContractMap = (IAccountDataProvider) await _accountDataProvider.GetMapAsync(SMART_CONTRACT_MAP_KEY);
var smartContractMap = _accountDataProvider.GetDataProvider().GetDataProvider(SMART_CONTRACT_MAP_KEY);
await smartContractMap.SetAsync(reg.Hash, reg);
}
}
Expand Down
9 changes: 3 additions & 6 deletions AElf.Kernel/SmartContractRegistration.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
namespace AElf.Kernel
{


public class SmartContractRegistration : ISerializable
{

/// <summary>
/// 0: Smart Contract Zero
/// 1: C# bytes
/// 2: Javascript
/// </summary>
public int Category { get; set; }

public IHash Hash { get; set; }

public byte[] Bytes { get; set; }

public byte[] Serialize()
{
throw new System.NotImplementedException();
Expand Down
1 change: 1 addition & 0 deletions AElf.Kernel/TransactionExecutingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public Task ExecuteAsync(ITransaction tx)
var task = Task.Factory.StartNew(() =>
{
var a = 1 + 1;
a += 1;
});
return task;
}
Expand Down

0 comments on commit 826dabc

Please sign in to comment.