Skip to content

Commit

Permalink
add VM state; import keys from file; adjust ui;
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Zhang committed Oct 22, 2016
1 parent 827b062 commit e4d4df5
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 151 deletions.
1 change: 1 addition & 0 deletions AntSharesCore/AntSharesCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
<Compile Include="Core\Scripts\IApiService.cs" />
<Compile Include="Core\Scripts\InterfaceEngine.cs" />
<Compile Include="Core\Scripts\Script.cs" />
<Compile Include="Core\Scripts\VMState.cs" />
<Compile Include="Core\Scripts\StackItem.cs" />
<Compile Include="Cryptography\BloomFilter.cs" />
<Compile Include="Cryptography\ECC\ECDsa.cs" />
Expand Down
286 changes: 144 additions & 142 deletions AntSharesCore/Core/Scripts/ScriptEngine.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions AntSharesCore/Core/Scripts/ScriptOp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public enum ScriptOp : byte
OP_RET = 0x66,
OP_APPCALL = 0x67,
OP_SYSCALL = 0x68,
OP_VERIFY = 0x69, // Marks transaction as invalid if top stack value is not true. True is removed, but false is not.
OP_HALT = 0x6A, // Marks transaction as invalid.
OP_HALTIFNOT = 0x69,
OP_HALT = 0x6A,


// Stack
Expand Down
12 changes: 12 additions & 0 deletions AntSharesCore/Core/Scripts/VMState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace AntShares.Core.Scripts
{
[Flags]
internal enum VMState : byte
{
NONE = 0,
HALT = 1 << 0,
FAULT = 1 << 1
}
}
36 changes: 31 additions & 5 deletions AntSharesDaemon/Shell/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private bool OnHelpCommand(string[] args)
"\tlist address\n" +
"\tlist asset\n" +
"\tcreate address [n=1]\n" +
"\timport key <wif>\n" +
"\timport key <wif|path>\n" +
"\tsend <id|alias> <address> <value> [fee=0]\n" +
"Node Commands:\n" +
"\tshow state\n" +
Expand Down Expand Up @@ -164,10 +164,36 @@ private bool OnImportKeyCommand(string[] args)
Console.WriteLine("error");
return true;
}
Account account = Program.Wallet.Import(args[2]);
Contract contract = Program.Wallet.GetContracts(account.PublicKeyHash).First(p => p.IsStandard);
Console.WriteLine($"address: {contract.Address}");
Console.WriteLine($" pubkey: {account.PublicKey.EncodePoint(true).ToHexString()}");
byte[] prikey = null;
try
{
prikey = Wallet.GetPrivateKeyFromWIF(args[2]);
}
catch (FormatException) { }
if (prikey == null)
{
string[] lines = File.ReadAllLines(args[2]);
for (int i = 0; i < lines.Length; i++)
{
if (lines[i].Length == 64)
prikey = lines[i].HexToBytes();
else
prikey = Wallet.GetPrivateKeyFromWIF(lines[i]);
Program.Wallet.CreateAccount(prikey);
Array.Clear(prikey, 0, prikey.Length);
Console.SetCursorPosition(0, Console.CursorTop);
Console.Write($"[{i + 1}/{lines.Length}]");
}
Console.WriteLine();
}
else
{
Account account = Program.Wallet.CreateAccount(prikey);
Array.Clear(prikey, 0, prikey.Length);
Contract contract = Program.Wallet.GetContracts(account.PublicKeyHash).First(p => p.IsStandard);
Console.WriteLine($"address: {contract.Address}");
Console.WriteLine($" pubkey: {account.PublicKey.EncodePoint(true).ToHexString()}");
}
return true;
}

Expand Down
1 change: 1 addition & 0 deletions AntSharesUI/UI/ClaimForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 24 additions & 2 deletions AntSharesUI/UI/ClaimForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,35 @@ public ClaimForm()
InitializeComponent();
}

private void CalculateClaimAmountUnavailable(uint height)
{
textBox2.Text = Wallet.CalculateClaimAmountUnavailable(Program.CurrentWallet.FindUnspentCoins().Where(p => p.AssetId.Equals(Blockchain.AntShare.Hash)).Select(p => p.Input), height).ToString();
}

private void ClaimForm_Load(object sender, EventArgs e)
{
Fixed8 amount_available = Wallet.CalculateClaimAmount(Program.CurrentWallet.GetUnclaimedCoins().Select(p => p.Input));
Fixed8 amount_unavailable = Wallet.CalculateClaimAmountUnavailable(Program.CurrentWallet.FindUnspentCoins().Where(p => p.AssetId.Equals(Blockchain.AntShare.Hash)).Select(p => p.Input), Blockchain.Default.Height);
textBox1.Text = amount_available.ToString();
textBox2.Text = amount_unavailable.ToString();
if (amount_available == Fixed8.Zero) button1.Enabled = false;
CalculateClaimAmountUnavailable(Blockchain.Default.Height);
Blockchain.PersistCompleted += Blockchain_PersistCompleted;
}

private void ClaimForm_FormClosing(object sender, FormClosingEventArgs e)
{
Blockchain.PersistCompleted -= Blockchain_PersistCompleted;
}

private void Blockchain_PersistCompleted(object sender, Block block)
{
if (InvokeRequired)
{
BeginInvoke(new Action<object, Block>(Blockchain_PersistCompleted), sender, block);
}
else
{
CalculateClaimAmountUnavailable(block.Height);
}
}

private void button1_Click(object sender, EventArgs e)
Expand Down

0 comments on commit e4d4df5

Please sign in to comment.