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

[Testnet] Bank contract #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions Testnet/Bank/Bank.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
25 changes: 25 additions & 0 deletions Testnet/Bank/Bank.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31729.503
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bank", "Bank.csproj", "{98E7D3F3-D13D-4D49-9FB1-664AD997557A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{98E7D3F3-D13D-4D49-9FB1-664AD997557A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{98E7D3F3-D13D-4D49-9FB1-664AD997557A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98E7D3F3-D13D-4D49-9FB1-664AD997557A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98E7D3F3-D13D-4D49-9FB1-664AD997557A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5EE600F5-16E3-46F5-855F-C68AA3B6778B}
EndGlobalSection
EndGlobal
105 changes: 105 additions & 0 deletions Testnet/Bank/BankContract.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using Stratis.SmartContracts;

/// <summary>
/// A useless contract that stores the funds you send it until you withdraw them.
/// </summary>
[Deploy]
public class BankContract : SmartContract
{
public BankContract(ISmartContractState contractState) : base(contractState)
{
}

public ulong GetContractBalance()
{
return this.Balance;
}

public ulong GetBalance(Address address)
{
return this.State.GetUInt64($"Balance:{address}");
}

/// <summary>
/// Test withdrawing deposited funds from a contract.
/// </summary>
public void Withdraw()
{
var balance = GetBalance(Message.Sender);

Assert(balance > 0, "Sender does not have a balance");

this.State.SetUInt64($"Balance:{Message.Sender}", 0);

var transferResult = Transfer(Message.Sender, balance);

Assert(transferResult.Success, "Withdrawal transfer failed!");

Log(new WithdrawLog
{
To = Message.Sender,
Amount = balance
});
}

/// <summary>
/// Test sending funds to a method.
/// </summary>
public void Deposit()
{
this.Receive();
}

/// <summary>
/// Test sending funds directly to a contract.
/// </summary>
public override void Receive()
{
var currentBalance = GetBalance(Message.Sender);
var newBalance = currentBalance + Message.Value;
this.State.SetUInt64($"Balance:{Message.Sender}", newBalance);

this.Log(new ReceiveLog
{
From = Message.Sender,
Amount = Message.Value,
Balance = newBalance
});
}

/// <summary>
/// Stores arbitrary string data under a key/value for the sender.
/// </summary>
public void StoreData(string key, string value)
{
this.State.SetString($"{Message.Sender}:{key}", value);
}

/// <summary>
/// Returns string data stored under a key for the sender.
/// </summary>
public string GetData(string key)
{
return this.State.GetString($"{Message.Sender}:{key}");
}

public struct ReceiveLog
{
[Index]
public Address From;

[Index]
public ulong Amount;

public ulong Balance;
}

public struct WithdrawLog
{
[Index]
public Address To;

[Index]
public ulong Amount;
}
}
15 changes: 15 additions & 0 deletions Testnet/Bank/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Bank Contract

**Compiler Version**
```
v2.0.0
```
**Contract Hash**
```
48d098400b8661fe1dcd1ceb73052fbd96a1a5a7e90d2035c4040b09fa7221f6
```

**Contract Byte Code**
```
4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C010200924BC4B90000000000000000E00022200B013000000A000000020000000000008E2900000020000000400000000000100020000000020000040000000000000004000000000000000060000000020000000000000300408500001000001000000000100000100000000000001000000000000000000000003C2900004F000000000000000000000000000000000000000000000000000000004000000C000000202900001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E746578740000009409000000200000000A000000020000000000000000000000000000200000602E72656C6F6300000C0000000040000000020000000C0000000000000000000000000000400000420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000702900000000000048000000020005000C220000140700000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000220203280600000A2A1E02280700000A2A7202280800000A7201000070038C08000001280900000A6F0A00000A2A00001330030097000000010000110202280B00000A6F0C00000A28030000060A0206166AFE037219000070280D00000A02280800000A720100007002280B00000A6F0C00000A8C08000001280900000A166A6F0E00000A0202280B00000A6F0C00000A06280F00000A0B02076F1000000A7257000070280D00000A021202FE1504000002120202280B00000A6F0C00000A7D040000041202067D0500000408280100002B2A1E026F1200000A2A001330030080000000020000110202280B00000A6F0C00000A280300000602280B00000A6F1300000AD70A02280800000A720100007002280B00000A6F0C00000A8C08000001280900000A066F0E00000A021201FE1503000002120102280B00000A6F0C00000A7D01000004120102280B00000A6F1300000A7D020000041201067D0300000407280200002B2AA202280800000A728F00007002280B00000A6F0C00000A8C0800000103281400000A046F1500000A2A9E02280800000A728F00007002280B00000A6F0C00000A8C0800000103281400000A6F1600000A2A00000042534A4201000100000000000C00000076342E302E33303331390000000005006C0000009C020000237E0000080300009002000023537472696E67730000000098050000A0000000235553003806000010000000234755494400000048060000CC00000023426C6F62000000000000000200000157150200090A000000FA013300160000010000000F0000000400000005000000080000000500000016000000080000000200000001000000020000000200000002000000000081010100000000000600E100CF0106002001CF010600CD00BC010F00EF0100000A0010011A020A0045021A020A009A001A020A000A021A020A0062021A020600860093010A0001011A020A00BC001A020600630193010600530293010A0071001A02000000001500000000000100010001001000380200001900010001000A0110006A0100002900010009000A0110007501000029000400090006009A018600060072028A00060069008A0006009F018600060072028A005020000000008618B601100001005920000000008600530016000200612000000000860066008D000200802000000000860080020600030023210000000086005A02060003002C2100000000C6004E0106000300B8210000000086001E0072000300E12100000000860028007800050000000100AE000000010012020000010089020000020048010000010089020900B60101001100B60106001900B6010A002900B60106005900B60106003100B6011000310047001600310090001A00690031021F0061000100250031007A0032007900A2013700310079023C0061000B0042003100AD0148004900FE01500031007D01540031004E01060079003E011600690031026B0061006001720061005601780021002B00C4002E000B0093002E0013009C002E001B00BB0041002B00C40043002300C40081002B00C400A1002B00C4002A006000048000000000000000000000000000000000450200000400000000000000000000007D0030000000000002000000000000000000000000001A0200000000030002000400020023005B002300660000000047657455496E7436340053657455496E743634003C4D6F64756C653E0053746F72654461746100476574446174610053797374656D2E507269766174652E436F72654C6962006765745F42616C616E636500476574436F6E747261637442616C616E63650047657442616C616E636500494D657373616765006765745F4D6573736167650056616C756554797065006765745F53746174650049536D617274436F6E7472616374537461746500636F6E74726163745374617465004950657273697374656E7453746174650044656275676761626C6541747472696275746500436F6D70696C6174696F6E52656C61786174696F6E7341747472696275746500496E646578417474726962757465004465706C6F794174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465006765745F56616C75650076616C7565005265636569766500476574537472696E6700536574537472696E6700526563656976654C6F670057697468647261774C6F6700536D617274436F6E74726163742E646C6C0053797374656D0046726F6D00546F006765745F53656E646572005472616E73666572002E63746F720053797374656D2E446961676E6F73746963730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300446562756767696E674D6F646573006765745F537563636573730041646472657373006164647265737300537472617469732E536D617274436F6E74726163747300466F726D61740042616E6B436F6E747261637400536D617274436F6E7472616374004F626A656374004465706F73697400495472616E73666572526573756C7400416D6F756E7400417373657274005769746864726177006B6579000000000017420061006C0061006E00630065003A007B0030007D00003D530065006E00640065007200200064006F006500730020006E006F00740020006800610076006500200061002000620061006C0061006E006300650000375700690074006800640072006100770061006C0020007400720061006E00730066006500720020006600610069006C00650064002100000F7B0030007D003A007B0031007D000000A1F93815CE64254883930A7E957EA1290004200101080320000105200101111105200101121D0320000B04200012310500020E0E1C0420010B0E0707030B12251110042000123D042000112105200201020E052002010E0B072002122511210B0320000206300101011E00040A0111100507020B110C040A01110C0600030E0E1C1C052002010E0E0420010E0E087CEC85D7BEA7798E0306112102060B0520010B11210801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F7773010801000200000000000401000000000000000000000000000000000000100000000000000000000000000000006429000000000000000000007E29000000200000000000000000000000000000000000000000000070290000000000000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF2500200010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000C000000903900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
```