Comments (18)
It seems that there is a general issue with ToString().
The following code is also causing an error:
public static string TestString()
{
return "Jimmy".ToString();
}
Invoke results:
Gas Consumed: 0.0246507 GAS
Exception: An unhandled exception was thrown. The value 2 is out of range.
Result: [ ]
from neo-devpack-dotnet.
@cschuchardt88 I think what @lock9 want to say is it is normal C# operation, neo should allow it work that way. Not about how to make it work, but how it should work.
from neo-devpack-dotnet.
Use primitive types. For example string
not String
.
Map<string, string> myNft = new();
myNft["name"] = "My NFT";
myNft["description"] = "My NFT Description";
var tokenString = myNft;
from neo-devpack-dotnet.
It works fine. Remove the .ToString
. This was on TestNet T5
public static void Test()
{
Map<string, string> myNft = new();
myNft["name"] = "My NFT";
myNft["description"] = "My NFT Description";
var tokenString = myNft;
}
from neo-devpack-dotnet.
This line is wrong var nftString = nftProperties.ToString();
You can't do that.
from neo-devpack-dotnet.
It seems that there is a general issue with ToString(). The following code is also causing an error:
public static string TestString() { return "Jimmy".ToString(); }
Invoke results: Gas Consumed: 0.0246507 GAS Exception: An unhandled exception was thrown. The value 2 is out of range. Result: [ ]
What don't you understand?
YOU CAN'T DO THAT!!!!!!!!!!!!
YOU CAST!!!!!!!!!!!
from neo-devpack-dotnet.
I did not see the same exception.... tests pass
from neo-devpack-dotnet.
from neo-devpack-dotnet.
@Jim8y Its an ApplicationEngine
Error. But It's because of non-primitive types.
from neo-devpack-dotnet.
I mean, why can't I reproduce the error.
from neo-devpack-dotnet.
He said
However, if I return the map and print it locally, it works.
So try blockchain?
from neo-devpack-dotnet.
I'll wait for Rick to explain it.
from neo-devpack-dotnet.
Hello.
Could it be my compiler version? What version are you using? I'm using Devpack 3.6.2
This doesn't work:
var nftProperties = new Map<string, string>();
nftProperties["key1"] = "value1";
nftProperties["key2"] = "value2";
var nftString = nftProperties.ToString();
This does work:
var nftProperties = new Map<string, string>();
nftProperties["key1"] = "value1";
nftProperties["key2"] = "value2";
var nftString = StdLib.Serialize(nftProperties);
from neo-devpack-dotnet.
I am using the master of devpack tested your code in one of the test contracts, nothing happens, build and run normally.
from neo-devpack-dotnet.
I was using the analyzer branch. I switched to the master branch, rebuilt it and got the same results.
Is there any chance that the error is in Neo Express?
Here is the file:
using System;
using System.ComponentModel;
using System.Numerics;
using Neo;
using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Attributes;
using Neo.SmartContract.Framework.Native;
using Neo.SmartContract.Framework.Services;
namespace NFTCollection
{
[DisplayName("CSharpNFT")]
[ManifestExtra("Author", "Linkd Academy")]
[ManifestExtra("Description", "NFT Contract Example")]
[ContractPermission("*", "onNEP11Payment")]
public class NFTCollection : SmartContract
{
static readonly byte[] KeyTotalSupply = { 0x01 };
static readonly byte[] KeyOwner = { 0x02 };
static readonly byte[] PrefixTokenId = { 0x03 };
static readonly byte[] PrefixToken = { 0x04 };
static readonly byte[] PrefixAccountToken = { 0x05 };
static readonly byte[] PrefixBalance = { 0x06 };
public delegate void OnTransferDelegate(UInt160 from, UInt160 to, BigInteger amount, ByteString tokenId);
[DisplayName("Transfer")]
public static event OnTransferDelegate OnTransfer;
[Safe]
public static string Symbol()
{
return "NFTS";
}
[Safe]
public static int Decimals()
{
return 0;
}
[Safe]
public static BigInteger TotalSupply()
{
return (BigInteger)Storage.Get(KeyTotalSupply);
}
[Safe]
public static UInt160 OwnerOf(string tokenId)
{
return (UInt160)Storage.Get(PrefixToken.Concat(tokenId));
}
public class MyNFT
{
public string name;
public string description;
public string tokenId;
public Map<string, string> properties = new Map<string, string>();
}
public static MyNFT CreateNFT()
{
var nftName = "My NFT";
var nftDescription = "My NFT Description";
var nftProperties = new Map<string, string>();
nftProperties["key1"] = "value1";
nftProperties["key2"] = "value2";
var nftString = nftProperties.ToString();
// var nftString = StdLib.Serialize(nftProperties);
// Runtime.Notify("Debug", new object[] { nftString });
// Generate Token ID
var serializedProperties = StdLib.Serialize(nftProperties);
var transactionHash = (Transaction)Runtime.ScriptContainer;
var tokenHashInput = serializedProperties.Concat(transactionHash.Hash);
var tokenId = CryptoLib.Ripemd160(tokenHashInput);
var myNft = new MyNFT()
{
name = nftName,
description = nftDescription,
properties = nftProperties,
tokenId = tokenId
};
return myNft;
}
public static object TestNFT()
{
var transaction = (Transaction)Runtime.ScriptContainer;
var sender = transaction.Sender;
var nft = CreateNFT();
var serializedNFT = StdLib.Serialize(nft);
var tokenDetailsKey = PrefixToken.Concat(nft.tokenId);
//Persist the NFT
Storage.Put(tokenDetailsKey, serializedNFT);
//Persist the owner of the NFT
Storage.Put(PrefixTokenId.Concat(nft.tokenId), sender);
var existingTokens = Storage.Get(PrefixAccountToken.Concat(sender));
List<ByteString> deserializedTokens;
if (existingTokens is null)
{
deserializedTokens = new ByteString[] { };
}
else
{
deserializedTokens = (ByteString[])StdLib.Deserialize(existingTokens);
}
//Persist the NFT in the account
deserializedTokens.Add(nft.tokenId);
Storage.Put(PrefixAccountToken.Concat(sender), StdLib.Serialize(deserializedTokens));
// Update the balance of the sender
var balance = (BigInteger)Storage.Get(PrefixBalance.Concat(sender));
var newBalance = balance + 1;
Storage.Put(PrefixBalance.Concat(sender), newBalance);
//Increase the total supply
var totalSupply = (BigInteger)Storage.Get(KeyTotalSupply);
var newTotalSupply = totalSupply + 1;
Storage.Put(KeyTotalSupply, newTotalSupply);
return nft;
}
public static object Properties(string tokenId)
{
var rawNFT = Storage.Get(PrefixToken.Concat(tokenId));
if (rawNFT is null)
{
throw new Exception("Token does not exist");
}
var nft = (MyNFT)StdLib.Deserialize(rawNFT);
return nft.properties;
}
public static Iterator TokensOf(UInt160 account)
{
if (account is null || !account.IsValid)
throw new Exception("Invalid Parameter.");
var accountKey = PrefixAccountToken.Concat(account);
var tokenIds = (Iterator)StdLib.Deserialize(Storage.Get(accountKey));
return tokenIds;
}
[DisplayName("_deploy")]
public static void Deploy(object data, bool update)
{
if (update) return;
Storage.Put(KeyTotalSupply, 0);
var tx = (Transaction)Runtime.ScriptContainer;
Storage.Put(KeyOwner, tx.Sender);
}
[Safe]
public static BigInteger BalanceOf(UInt160 account)
{
if (account is null || !account.IsValid)
throw new Exception("Invalid Parameter.");
BigInteger balance = (BigInteger)Storage.Get(PrefixBalance.Concat(account));
return balance;
}
public static bool Transfer(UInt160 from, UInt160 to, String tokenId, object data)
{
if (from is null || !from.IsValid)
throw new Exception("Invalid from address.");
if (to is null || !to.IsValid)
throw new Exception("Invalid to address.");
if (!Runtime.CheckWitness(from))
throw new Exception("Invalid Signature");
var tokenOwner = (UInt160)Storage.Get(PrefixTokenId.Concat(tokenId));
if (tokenOwner is null)
throw new Exception("Token does not exist");
if (tokenOwner != from)
throw new Exception("Not Authorized");
if (from == to)
return true;
Storage.Put(PrefixTokenId.Concat(tokenId), to);
Storage.Put(PrefixBalance.Concat(from), BalanceOf(from) - 1);
Storage.Put(PrefixBalance.Concat(to), BalanceOf(to) + 1);
if (ContractManagement.GetContract(to) is not null)
{
Contract.Call(to, "onNEP11Payment", CallFlags.All, from, 1, tokenId, data);
}
OnTransfer(from, to, 1, tokenId);
return true;
}
public static void Update(ByteString nefFile, string manifest, object data)
{
if (Runtime.CheckWitness((UInt160)Storage.Get(KeyOwner)))
ContractManagement.Update(nefFile, manifest, data);
}
}
}
from neo-devpack-dotnet.
Well than say that. After 20 times of telling him why he can't do something. He keeps saying I can't do this.
- It shows he doesn't read everything.
- It wastes our time.
from neo-devpack-dotnet.
Well than say that. After 20 times of telling him why he can't do something. He keeps saying I can't do this.
- It shows he doesn't read everything.
- It wastes our time.
from neo-devpack-dotnet.
Hi @Jim8y ,
I've looked into the UT that you used. It's not checking the VM State.
from neo-devpack-dotnet.
Related Issues (20)
- "\xff" is parsed as weird bytes HOT 1
- Make `Runtime.ScriptContainer` return a Transaction object HOT 8
- Add support to Array.Empty HOT 1
- `BigInteger` comparer for `ByteString` HOT 17
- Move TestClasses into a separate project
- UTs are not working on macOS / VSCode
- Automatically include "Debug" event when building in debug mode
- How can we avoid problems with different .NET versions? What's the best way to distribute the compiler? HOT 9
- Create a TestEngine HOT 21
- StoredAttribute default value when integer is not working
- Release workflow doesn't work HOT 2
- Use github packages without user and password HOT 7
- Neo submodule issue HOT 6
- Release workflow may not work HOT 2
- Fix hardcoded version for packing
- Update neo submodule
- TestEngine: Coverage and test current smart contracts
- Allow to compile a cs files without a project
- Avoid reuse the same namespace in devpack HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from neo-devpack-dotnet.