Skip to content

Conversation

@Neurosploit
Copy link
Contributor

@Neurosploit Neurosploit commented Sep 5, 2019

This pull request hopes to deliver a smart contract sample that implements the erc-721 standard as a stratis smart contract equivalent.

Notes:

  • this contract does not implement a mint and/or burn method so is unusable without it (just like the original standard). It is up to the implementer to think about the minting and/or burning implementation the implementer needs before the contract can be used. Should I add this in a readme on the solution level?
  • I would like to see some discussion in this PR regarding how we should use the supportedinterface standards on the stratis blockchain, I think it's a good idea to have, yet the actual implementation of it can vary. Please comment on it.
  • I have not used the smart contact testing tool yet to verify the contract's validity. I hope to do that this weekend and fix any flaws that may be raised. I think it can be code reviewed without this already. This also will include trying to create a mint/burn method in a local implementation
    and try it on a local testnet sidechain.
  • the contract was ported from the 0xcert reference implementation and just included the base implementation.

@mrtpain
Copy link

mrtpain commented Sep 7, 2019

Hey! Overall, looking good! I briefly looked over the code but at the moment, I'm unfamiliar with the erc-721 standard. Give me some time to look over that and pull this PR in locally and I can review on a more granular level.

@Neurosploit
Copy link
Contributor Author

Neurosploit commented Sep 16, 2019

A few things I noticed whilst using the sct tool: see comments on files.

/// <summary>
/// A non fungible token contract.
/// </summary>
public class NonFungibleToken : SmartContract, INonFungibleToken, ISupportsInterface
Copy link
Contributor Author

@Neurosploit Neurosploit Sep 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are multiple files and interfaces on the smartcontract class not supported by sct? Hard to keep things reusable and structured otherwise. I can create an abstract base class but interfaces are way nicer to work with and are easily copied between projects.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tried to keep the amount of functionality minimal in the first iteration. I definitely hear what you're saying about the interfaces, this is something we could look into support for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should I do about this now? Leave it out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also look into namespaces, why can't that work if the class is public?

if (this.PersistentState.IsContract(to))
{
ITransferResult result = this.Call(to, 0, "OnNonFungibleTokenReceived", new object[] { this.Message.Sender, from, tokenId, data }, 0);
Assert(Convert.ToBoolean(result.ReturnValue));
Copy link
Contributor Author

@Neurosploit Neurosploit Sep 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From SCT:
System.Convert is not supported so I also have no way of converting this with a system class.
Why does Call return an result.ReturnValue object which I can't cast in any way too a bool? I also don't have a generic type of any sorts to pass an assumed value.
I can also not cast to Nullable < bool > to resolve the compiler error I get thus making it pretty hard to work with.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to cast it using (bool)result.ReturnValue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, see commit after this comment.

@Neurosploit
Copy link
Contributor Author

Neurosploit commented Sep 17, 2019

After some more changes, removing the namespace and the interfaces this now validates:

Smart Contract Validator

Reading F:\Github\WorkingDir\StratisSmartContractsSamples\src\NonFungibleToken\NonFungibleToken\NonFungibleToken.cs
Read F:\Github\WorkingDir\StratisSmartContractsSamples\src\NonFungibleToken\NonFungibleToken\NonFungibleToken.cs OK

Compiling...
Compilation OK

Building ModuleDefinition
ModuleDefinition built successfully

Validating file F:\Github\WorkingDir\StratisSmartContractsSamples\src\NonFungibleToken\NonFungibleToken\NonFungibleToken.cs...

====== Smart Contract Validation results for file F:\Github\WorkingDir\StratisSmartContractsSamples\src\NonFungibleToken\NonFungibleToken\NonFungibleToken.cs ======
Compilation Result
Compilation OK: True

Format Validation Result
Format Valid: True

Determinism Validation Result
Determinism Valid: True



Hash
78d8fe37c54db4f678909d8c6e8ad613bb2e43ad0d95f7ee82bb5e95ed365d59

ByteCode
4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C010200B02872DF0000000000000000E00022200B013000001400000002000000000000EA330000002000000040000000000010002000000002000004000000000000000400000000000000006000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000983300004F000000000000000000000000000000000000000000000000000000004000000C0000007C3300001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E74657874000000F0130000002000000014000000020000000000000000000000000000200000602E72656C6F6300000C000000004000000002000000160000000000000000000000000000400000420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000CC330000000000004800000002000500F4250000880D000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007202280500000A7201000070038C0C000001280600000A6F0700000A2A7602280500000A7201000070038C0C000001280600000A046F0800000A2A46722F000070038C0F000001280600000A2A4E02280500000A020328030000066F0900000A2A5202280500000A02032803000006046F0A00000A2A46724B000070038C0F000001280600000A2A4E02280500000A020328060000066F0900000A2A5202280500000A02032806000006046F0A00000A2A7202280500000A726D000070038C06000001280600000A6F0B00000A2A7602280500000A726D000070038C06000001280600000A046F0C00000A2A8A02280500000A729D000070038C06000001048C06000001280D00000A6F0700000A2A8E02280500000A729D000070038C06000001048C06000001280D00000A056F0800000A2A820203280E00000A0217172802000006021817280200000602191628020000062A22020328010000062A32020304050E04281B0000062A4202030405168D10000001281B0000062A001330030047000000010000110205282100000602052822000006020528040000060A020603280F00000A72CD000070281000000A02047E1100000A281200000A72CD000070281000000A02040528180000062A00133004003A000000010000110204282000000602042822000006020428040000060A020306281200000A72CD000070281000000A020403280800000602060304281E0000062A9E0202281300000A6F1400000A0304280C0000060202281300000A6F1400000A0304281F0000062A7A02037E1100000A281200000A72CD000070281000000A020328090000062A000000133003002000000001000011020328040000060A02067E1100000A281200000A72CD000070281000000A062A3E02032822000006020328070000062A26020304280B0000062A0000133004002900000001000011020428040000060A0204281C0000060206042819000006020304281A00000602060304281D0000062AF2020204280400000603280F00000A72CD000070281000000A020302032809000006176ADB280A00000602280500000A020428030000066F1500000A2A000013300400380000000200001102020428040000067E1100000A280F00000A72CD000070281000000A0204032805000006020328090000060A020306176AD7280A0000062A13300800AC000000030000110205282100000602052822000006020528040000060A020603280F00000A72CD000070281000000A02047E1100000A281200000A72CD000070281000000A020405281800000602280500000A046F1600000A2C570204166A72EB0000701A8D0E000001251602281300000A6F1400000A8C06000001A22517038C06000001A22518058C0F000001A225190E04A2166A281700000A0B02076F1800000AA51200000172CD000070281000000A2A9A020328070000067E1100000A281200000A2C1202280500000A020328060000066F1500000A2A00133003002800000004000011021200FE15030000021200037D010000041200047D020000041200057D0300000406280100002B2A133003002800000005000011021200FE15040000021200037D040000041200047D050000041200057D0600000406280200002B2A133003002800000006000011021200FE15050000021200037D070000041200047D080000041200057D0900000406280300002B2A133004003C00000001000011020328040000060A020602281300000A6F1400000A280F00000A2D14020602281300000A6F1400000A280B0000062B011772CD000070281000000A2A133004005500000001000011020328040000060A020602281300000A6F1400000A280F00000A2D2D0203280700000602281300000A6F1400000A280F00000A2D14020602281300000A6F1400000A280B0000062B011772CD000070281000000A2A7602020328040000067E1100000A281200000A72CD000070281000000A2A0042534A4201000100000000000C00000076342E302E33303331390000000005006C000000D0050000237E00003C060000C004000023537472696E677300000000FC0A00002401000023555300200C0000100000002347554944000000300C00005801000023426C6F62000000000000000200000157150200090A000000FA01330016000001000000120000000500000009000000220000003F000000190000000B00000006000000010000000200000003000000030000000000610201000000000006001001A00306003F01A0030600FC005F030F00C00300000A002604FD030A00ED03FD030A00BD00FD030A003B04FD030600A80083020A003001FD030A00D100FD0306000100830206009201830206003404830206001500830206005D0183020A009300FD030600A0028302000000001C00000000000100010001001000CE0200001500010001000A011000B70100002500010023000A011000990100002500040023000A011000A5010000250007002300060096025E000600DF025E0006005900C000060027035E0006006C005E0006005900C000060027035E00060050035E0006006C00C30050200000000081007203C60001006D200000000081008903CB0002008B200000000081009304D10004009D200000000081001303D6000500B1200000000081002003DC000600C6200000000081008004D1000800D820000000008100F901D6000900EC200000000081000902DC000A0001210000000081004B04E3000C001E210000000081006204E9000D003C210000000081003303F0000F005F210000000081004603F80011008321000000008618590345001400A4210000000086008100C6001500AD210000000086008A0201011600BA210000000086008A020C011A00CC210000000086008E020C011D0020220000000086007801E900200066220000000086004A02150122008E220000000086008001E3002400B0220000000086008A01D6002500DC220000000086006900D6002600EC220000000086002702F0002700F822000000008100DC01E90029002D23000000008100C002E9002B006C23000000008100A802E9002D00B023000000008100C30101012F00682400000000810019021C0133009024000000008100FB020C013400C424000000008100ED010C013700F8240000000081003802F8003A002C25000000008100B2001C013D00742500000000810007031C013E00D525000000008100B3021C013F00000001004D00000001004D00000002007201000001007E00000001007E00000001007E00000002007201000001007E00000001007E00000001007E0000000200720100000100F50300000100F503000002007201000001002D0300000200CF03000001002D0300000200CF0300000300720100000100F600000001002500000001009B0200000200E702000003006100000004003100000001009B0200000200E702000003006100000001009B0200000200E70200000300610000000100750000000200610000000100CF03000002007500000001002D03000001006100000001006100000001002D0300000200CF0300000100E702000002006100000001009B0200000200610000000100E702000002006100000001009B0200000200E702000003006100000004003100000001006100000001009B0200000200E702000003006100000001002D03000002007500000003006100000001002D0300000200CF03000003007500000001006100000001006100000001006100090059030100110059030600190059030A005100590306002900E2001000690014041500590073021B0059007B0220005900DF0326005900EA032C00590008003300590012003800690014043E002900590345003100A30450002900790458003100E2025E003100AF04500029009C0062008900F00267005900EA026C0059001B047C0029005C028200410062018E002900BF0197002100230052012E000B0021012E0013002A012E001B004901410023005201610023005201810023005201A10023005201C10023005201E100230052010101230052014B00710075009200A300AD0004800000000000000000000000000000000026040000040000000000000000000000B7003600000000000100020001000000000000000000FD030000000003000200040002000500020033009E003300A8003300B20000000055496E7433320047657455496E7436340053657455496E743634003C4D6F64756C653E00696E74657266616365494400646174610053797374656D2E507269766174652E436F72654C696200696E74657266616365496400546F6B656E496400746F6B656E496400476574417070726F76656400617070726F76656400696400537570706F727473496E7465726661636500494D657373616765006765745F4D6573736167650056616C7565547970650043616E4F7065726174650049536D617274436F6E74726163745374617465004950657273697374656E745374617465006765745F50657273697374656E7453746174650073746174650044656275676761626C6541747472696275746500436F6D70696C6174696F6E52656C61786174696F6E7341747472696275746500496E6465784174747269627574650052756E74696D65436F6D7061746962696C6974794174747269627574650042797465006765745F52657475726E56616C75650076616C756500417070726F76650042616C616E63654F66004F776E65724F6600537472696E6700417070726F76616C4C6F6700417070726F76616C466F72416C6C4C6F67005472616E736665724C6F6700536166655472616E7366657246726F6D496E7465726E616C005472616E73666572496E7465726E616C004C6F67417070726F76616C004765744964546F417070726F76616C005365744964546F417070726F76616C00436C656172417070726F76616C004973417070726F766564466F72416C6C004C6F67417070726F76616C466F72416C6C00536574417070726F76616C466F72416C6C0043616C6C00536D617274436F6E74726163742E646C6C00476574426F6F6C00536574426F6F6C0053797374656D00536166655472616E7366657246726F6D0066726F6D00426F6F6C65616E004164644E46546F6B656E0056616C69644E46546F6B656E0052656D6F76654E46546F6B656E004E6F6E46756E6769626C65546F6B656E00546F005A65726F00746F00436C656172006765745F53656E646572004C6F675472616E736665720043616E5472616E73666572004765744964546F4F776E6572005365744964546F4F776E6572006F776E6572004765744F776E6572546F4F70657261746F72005365744F776E6572546F4F70657261746F72002E63746F720053797374656D2E446961676E6F737469637300476574537570706F72746564496E746572666163657300536574537570706F72746564496E74657266616365730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300446562756767696E674D6F646573006F70657261746F724164647265737300476574416464726573730053657441646472657373006164647265737300537472617469732E536D617274436F6E74726163747300466F726D6174004973436F6E747261637400536D617274436F6E7472616374004F626A65637400495472616E73666572526573756C74004765744F776E6572546F4E46546F6B656E436F756E74005365744F776E6572546F4E46546F6B656E436F756E7400417373657274004765744964546F417070726F76616C4B6579004765744964546F4F776E65724B6579006F705F457175616C697479006F705F496E657175616C69747900000000002D53007500700070006F00720074006500640049006E0074006500720066006100630065003A007B0030007D00001B4900640054006F004F0077006E00650072003A007B0030007D0000214900640054006F0041007000700072006F00760061006C003A007B0030007D00002F4F0077006E006500720054006F004E00460054006F006B0065006E0043006F0075006E0074003A007B0030007D00002F4F0077006E006500720054006F004F00700065007200610074006F0072003A007B0030007D003A007B0031007D00001D41007300730065007200740020006600610069006C00650064002E0000354F006E004E006F006E00460075006E006700690062006C00650054006F006B0065006E0052006500630065006900760065006400000000004F2BD1F1756C2B48AAB494771649550F00042001010803200001052001011111042000122D0500020E0E1C042001020E052002010E0205200111190E062002010E11190420010B0E052002010E0B0600030E0E1C1C05200101121D0407011119070002021119111905200201020E0306111904200012450420001119042001010E0307010B060702111912210520010211190B2005122111190B0E1D1C0B0320001C040701110C06300101011E00040A01110C0407011110040A0111100407011114040A011114087CEC85D7BEA7798E02060B02060204200102090520020109020420010E0B05200111190B062002010B11190520010B11190620020111190B07200202111911190820030111191119020A200401111911190B1D0508200301111911190B06200201111902042001010B0801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F77730108010002000000000004010000000000000000000000000000000010000000000000000000000000000000C03300000000000000000000DA330000002000000000000000000000000000000000000000000000CC330000000000000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF250020001000000000000000000000000000000000003000000C000000EC3300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
======

}
catch (Exception ex)
{
if (ex is InvalidCastException || ex is NullReferenceException)
Copy link
Contributor Author

@Neurosploit Neurosploit Sep 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try catching also not supported, well then, the framework can deal with it.

Copy link
Collaborator

@codingupastorm codingupastorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry this has taken me so long to have a look at, I wasn't even aware of it.

Looks great to me, can't fault it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants