Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sender from signers #1752

Merged
merged 30 commits into from
Jul 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3702164
Sender from signers
shargon Jul 7, 2020
576973b
Remove co-
shargon Jul 7, 2020
a618ebf
Merge branch 'master' into sender-from-signers
shargon Jul 8, 2020
4d70d15
Move signers outside attributes
shargon Jul 8, 2020
d775492
Fix UT and remove Signers class
shargon Jul 9, 2020
fc6a3fa
Fix UT
shargon Jul 9, 2020
ec0262e
Add FeeOnly scope
shargon Jul 9, 2020
09860a4
Remove orderBy
shargon Jul 9, 2020
f4a6205
Merge branch 'master' into sender-from-signers
erikzhang Jul 10, 2020
a726699
Remove _signersCache
erikzhang Jul 10, 2020
67dc7e3
Fix Signers
erikzhang Jul 10, 2020
881fb88
Fix WitnessScope
erikzhang Jul 10, 2020
e55dfee
Fix Sender
erikzhang Jul 10, 2020
e28cd1d
Update TransactionAttributeType.cs
erikzhang Jul 10, 2020
eb7e302
Update Wallet.cs
erikzhang Jul 10, 2020
c536c30
Fix Wallet
erikzhang Jul 10, 2020
0f5db32
Rename
erikzhang Jul 10, 2020
8a8b837
Update Wallet.cs
erikzhang Jul 10, 2020
ffc55fe
Update Wallet.cs
erikzhang Jul 10, 2020
e018eb6
Partial UT fix
shargon Jul 10, 2020
59f934d
More UT fixes
shargon Jul 10, 2020
eea80a2
Fix Sender's WitnessScope
erikzhang Jul 10, 2020
cf8ffba
Fix Wallet
erikzhang Jul 10, 2020
6b4a56b
Fix UT
shargon Jul 10, 2020
a2ae4a2
Explicit FeeOnly for DeployNativeContracts
shargon Jul 10, 2020
f09a8a5
Same order as serialization
shargon Jul 10, 2020
4870875
Test FeeOnly
shargon Jul 10, 2020
abc7999
Merge branch 'master' into sender-from-signers
shargon Jul 10, 2020
cb8f978
dotnet format
shargon Jul 10, 2020
be47d0d
format
erikzhang Jul 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/neo/Wallets/Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,27 +288,28 @@ public Transaction MakeTransaction(TransferOutput[] outputs, UInt160 from = null
}
}

public Transaction MakeTransaction(byte[] script, UInt160 sender = null, Signer[] cosigners = null, TransactionAttribute[] attributes = null)
public Transaction MakeTransaction(byte[] script, Signer[] signers = null, TransactionAttribute[] attributes = null)
{
UInt160[] accounts;
if (sender is null)
if (signers is null || signers.Length > 0)
{
accounts = GetAccounts().Where(p => !p.Lock && !p.WatchOnly).Select(p => p.ScriptHash).ToArray();
}
else
{
var sender = signers[0].Account;
if (!Contains(sender))
throw new ArgumentException($"The address {sender} was not found in the wallet");
accounts = new[] { sender };
}
using (SnapshotView snapshot = Blockchain.Singleton.GetSnapshot())
{
var balances_gas = accounts.Select(p => (Account: p, Value: NativeContract.GAS.BalanceOf(snapshot, p))).Where(p => p.Value.Sign > 0).ToList();
return MakeTransaction(snapshot, script, cosigners ?? Array.Empty<Signer>(), attributes ?? Array.Empty<TransactionAttribute>(), balances_gas);
return MakeTransaction(snapshot, script, signers ?? Array.Empty<Signer>(), attributes ?? Array.Empty<TransactionAttribute>(), balances_gas);
}
}

private Transaction MakeTransaction(StoreView snapshot, byte[] script, Signer[] cosigners, TransactionAttribute[] attributes, List<(UInt160 Account, BigInteger Value)> balances_gas)
private Transaction MakeTransaction(StoreView snapshot, byte[] script, Signer[] signers, TransactionAttribute[] attributes, List<(UInt160 Account, BigInteger Value)> balances_gas)
shargon marked this conversation as resolved.
Show resolved Hide resolved
{
Random rand = new Random();
foreach (var (account, value) in balances_gas)
Expand All @@ -319,7 +320,7 @@ private Transaction MakeTransaction(StoreView snapshot, byte[] script, Signer[]
Nonce = (uint)rand.Next(),
Script = script,
ValidUntilBlock = snapshot.Height + Transaction.MaxValidUntilBlockIncrement,
Signers = cosigners.Prepend(new Signer { Account = account }).ToArray(),
Signers = signers.Prepend(new Signer { Account = account }).ToArray(),
Attributes = attributes,
};

Expand Down
4 changes: 2 additions & 2 deletions tests/neo.UnitTests/Consensus/UT_ConsensusContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private Transaction CreateTransactionWithSize(int v)
var tx = new Transaction()
{
Attributes = System.Array.Empty<TransactionAttribute>(),
Signers = System.Array.Empty<Signer>(),
Signers = new Signer[] { new Signer() { Account = UInt160.Zero } },
NetworkFee = 0,
Nonce = (uint)Environment.TickCount,
Script = new byte[0],
Expand All @@ -145,7 +145,7 @@ private Transaction CreateTransactionWithSytemFee(long fee)
var tx = new Transaction()
{
Attributes = System.Array.Empty<TransactionAttribute>(),
Signers = System.Array.Empty<Signer>(),
Signers = new Signer[] { new Signer() { Account = UInt160.Zero } },
NetworkFee = 0,
Nonce = (uint)Environment.TickCount,
Script = new byte[0],
Expand Down
6 changes: 3 additions & 3 deletions tests/neo.UnitTests/Ledger/UT_Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ public void TestContainsTransaction()
[TestMethod]
public void TestGetCurrentBlockHash()
{
Blockchain.Singleton.CurrentBlockHash.Should().Be(UInt256.Parse("0xc5e3965587c58ff2a38e3f152e054e5cbc6f114ac3d83c7189eb4bb73294679d"));
Blockchain.Singleton.CurrentBlockHash.Should().Be(UInt256.Parse("0xecaee33262f1bc7c7c28f2b25b54a5d61d50670871f45c0c6fe755a40cbde4a8"));
}

[TestMethod]
public void TestGetCurrentHeaderHash()
{
Blockchain.Singleton.CurrentHeaderHash.Should().Be(UInt256.Parse("0xc5e3965587c58ff2a38e3f152e054e5cbc6f114ac3d83c7189eb4bb73294679d"));
Blockchain.Singleton.CurrentHeaderHash.Should().Be(UInt256.Parse("0xecaee33262f1bc7c7c28f2b25b54a5d61d50670871f45c0c6fe755a40cbde4a8"));
}

[TestMethod]
Expand All @@ -91,7 +91,7 @@ public void TestGetBlock()
[TestMethod]
public void TestGetBlockHash()
{
Blockchain.Singleton.GetBlockHash(0).Should().Be(UInt256.Parse("0xc5e3965587c58ff2a38e3f152e054e5cbc6f114ac3d83c7189eb4bb73294679d"));
Blockchain.Singleton.GetBlockHash(0).Should().Be(UInt256.Parse("0xecaee33262f1bc7c7c28f2b25b54a5d61d50670871f45c0c6fe755a40cbde4a8"));
Blockchain.Singleton.GetBlockHash(10).Should().BeNull();
}

Expand Down
10 changes: 5 additions & 5 deletions tests/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void Serialize()
UInt256 val256 = UInt256.Zero;
TestUtils.SetupBlockWithValues(uut, val256, out var _, out var _, out var _, out var _, out var _, out var _, 1);

var hex = "000000000000000000000000000000000000000000000000000000000000000000000000ecba43e27d4cff6e139ae5c1424151aa41f8bcf1c89132d1a98a915740d271d9e913ff854c00000000000000000000000000000000000000000000000000000001000111020000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000010100010000";
var hex = "000000000000000000000000000000000000000000000000000000000000000000000000add6632f6f3d29cdf94555bb191fb5296683e5446f9937c56bb94c8608023044e913ff854c00000000000000000000000000000000000000000000000000000001000111020000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000001000100010000";
uut.ToArray().ToHexString().Should().Be(hex);
}

Expand All @@ -94,7 +94,7 @@ public void Deserialize()
UInt256 val256 = UInt256.Zero;
TestUtils.SetupBlockWithValues(new Block(), val256, out var merkRoot, out var val160, out var timestampVal, out var indexVal, out var scriptVal, out var transactionsVal, 1);

var hex = "000000000000000000000000000000000000000000000000000000000000000000000000ecba43e27d4cff6e139ae5c1424151aa41f8bcf1c89132d1a98a915740d271d9e913ff854c00000000000000000000000000000000000000000000000000000001000111020000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000010100010000";
var hex = "000000000000000000000000000000000000000000000000000000000000000000000000add6632f6f3d29cdf94555bb191fb5296683e5446f9937c56bb94c8608023044e913ff854c00000000000000000000000000000000000000000000000000000001000111020000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000001000100010000";

using (MemoryStream ms = new MemoryStream(hex.HexToBytes(), false))
using (BinaryReader reader = new BinaryReader(ms))
Expand Down Expand Up @@ -199,11 +199,11 @@ public void ToJson()

JObject jObj = uut.ToJson();
jObj.Should().NotBeNull();
jObj["hash"].AsString().Should().Be("0xbc31c72acd2f3af6a1bc8454c0956a5e7aa6301c755e70cc1bd9263c1d7cfcba");
jObj["hash"].AsString().Should().Be("0x9a164d5b9a1ab8745c97dbaaaef8eb30b0d80a00205acdc82daf502bee69bc20");
jObj["size"].AsNumber().Should().Be(167);
jObj["version"].AsNumber().Should().Be(0);
jObj["previousblockhash"].AsString().Should().Be("0x0000000000000000000000000000000000000000000000000000000000000000");
jObj["merkleroot"].AsString().Should().Be("0xd971d24057918aa9d13291c8f1bcf841aa514142c1e59a136eff4c7de243baec");
jObj["merkleroot"].AsString().Should().Be("0x44300208864cb96bc537996f44e5836629b51f19bb5545f9cd293d6f2f63d6ad");
jObj["time"].AsNumber().Should().Be(328665601001);
jObj["index"].AsNumber().Should().Be(0);
jObj["nextconsensus"].AsString().Should().Be("NKuyBkoGdZZSLyPbJEetheRhMjeznFZszf");
Expand All @@ -214,7 +214,7 @@ public void ToJson()

jObj["tx"].Should().NotBeNull();
JArray txObj = (JArray)jObj["tx"];
txObj[0]["hash"].AsString().Should().Be("0x85110746f54b4dc72502443c1bb1368ab256bbf3ea9f759b98a3f7861523e6e3");
txObj[0]["hash"].AsString().Should().Be("0x995ce8ff19c30f6b0d6b03e5ed8bd30b08027c92177923782d3a64f573421931");
txObj[0]["size"].AsNumber().Should().Be(53);
txObj[0]["version"].AsNumber().Should().Be(0);
((JArray)txObj[0]["attributes"]).Count.Should().Be(0);
Expand Down