Skip to content

Commit b159fd3

Browse files
committed
Merge branch 'dev-merge'
2 parents faa2b98 + 259f987 commit b159fd3

File tree

15 files changed

+273
-29
lines changed

15 files changed

+273
-29
lines changed

Phantasma.API/NexusAPI.cs

+29-5
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ public class NexusAPI
404404
public ITokenSwapper TokenSwapper;
405405
public Mempool Mempool;
406406
public Node Node;
407+
407408
public IEnumerable<APIEntry> Methods => _methods.Values;
408409

409410
private readonly Dictionary<string, APIEntry> _methods = new Dictionary<string, APIEntry>(StringComparer.InvariantCultureIgnoreCase);
@@ -608,9 +609,19 @@ private TokenDataResult FillNFT(string symbol, BigInteger ID, bool extended)
608609
}
609610
else
610611
{
611-
Blockchain.Tokens.TokenUtils.FetchProperty(Nexus.RootStorage, chain, method.name, series, ID, (propName, propValue) =>
612+
TokenUtils.FetchProperty(Nexus.RootStorage, chain, method.name, series, ID, (propName, propValue) =>
612613
{
613-
properties.Add(new TokenPropertyResult() { Key = propName, Value = propValue.AsString() });
614+
string temp;
615+
if (propValue.Type == VMType.Bytes)
616+
{
617+
temp = "0x" + Base16.Encode(propValue.AsByteArray());
618+
}
619+
else
620+
{
621+
temp = propValue.AsString();
622+
}
623+
624+
properties.Add(new TokenPropertyResult() { Key = propName, Value = temp });
614625
});
615626
}
616627
}
@@ -2116,9 +2127,22 @@ public IAPIResult GetPeers()
21162127
allPeers = allPeers.Where(x => !x.Endpoint.Host.Contains("localhost"));
21172128
}
21182129

2119-
var peers = allPeers.Select(x => new PeerResult() { url = x.Endpoint.ToString(), version = x.Version, flags = x.Capabilities.ToString(), fee = x.MinimumFee.ToString(), pow = (uint)x.MinimumPoW }).ToList();
2120-
2121-
peers.Add(new PeerResult() { url = $"{Node.PublicEndpoint}", version = Node.Version, flags = Node.Capabilities.ToString(), fee = Node.MinimumFee.ToString(), pow = (uint)Node.MinimumPoW });
2130+
var peers = allPeers.Select(x => new PeerResult() {
2131+
url = x.Endpoint.ToString(),
2132+
version = x.Version,
2133+
flags = x.Capabilities.ToString(),
2134+
fee = x.MinimumFee.ToString(),
2135+
pow = (uint)x.MinimumPoW,
2136+
ports = x.Ports.Select(y => new PortResult() { name = y.Name, port = y.Port}).ToArray()
2137+
}) .ToList();
2138+
2139+
peers.Add(new PeerResult() {
2140+
url = $"{Node.PublicEndpoint}",
2141+
version = Node.Version,
2142+
flags = Node.Capabilities.ToString(),
2143+
fee = Node.MinimumFee.ToString(),
2144+
pow = (uint)Node.MinimumPoW,
2145+
ports = this.Node.AvailablePorts.Select(y => new PortResult() { name = y.Name, port = y.Port }).ToArray() });
21222146

21232147
peers.Shuffle();
21242148

Phantasma.API/Structs.cs

+12
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,15 @@ public struct ReceiptResult : IAPIResult
592592
public string script;
593593
}
594594

595+
public struct PortResult: IAPIResult
596+
{
597+
[APIDescription("Port description")]
598+
public string name;
599+
600+
[APIDescription("Port number")]
601+
public int port;
602+
}
603+
595604
public struct PeerResult: IAPIResult
596605
{
597606
[APIDescription("URL of peer")]
@@ -608,6 +617,9 @@ public struct PeerResult: IAPIResult
608617

609618
[APIDescription("Minimum proof of work required by node")]
610619
public uint pow;
620+
621+
[APIDescription("List of exposed ports")]
622+
public PortResult[] ports;
611623
}
612624

613625
public struct ValidatorResult : IAPIResult

Phantasma.Blockchain/ExtCalls.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,17 @@ private static ExecutionState Runtime_MintToken(RuntimeVM vm)
10151015
seriesID = 0;
10161016
}
10171017

1018-
var tokenID = vm.MintToken(symbol, source, destination, rom, ram, seriesID);
1018+
Address creator;
1019+
if (vm.ProtocolVersion >= 7)
1020+
{
1021+
creator = source;
1022+
}
1023+
else
1024+
{
1025+
creator = destination;
1026+
}
1027+
1028+
var tokenID = vm.MintToken(symbol, creator, destination, rom, ram, seriesID);
10191029

10201030
var result = new VMObject();
10211031
result.SetValue(tokenID);

Phantasma.Blockchain/Nexus.cs

+20-5
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,8 @@ internal void MintToken(RuntimeVM Runtime, IToken token, Address source, Address
738738

739739
var nft = ReadNFT(Runtime, token.Symbol, tokenID);
740740
using (var m = new ProfileMarker("Nexus.WriteNFT"))
741-
WriteNFT(Runtime, token.Symbol, tokenID, Runtime.Chain.Name, destination, nft.ROM, nft.RAM, nft.SeriesID, nft.Timestamp, nft.Infusion, !isSettlement);
741+
WriteNFT(Runtime, token.Symbol, tokenID, Runtime.Chain.Name, source, destination, nft.ROM, nft.RAM,
742+
nft.SeriesID, nft.Timestamp, nft.Infusion, !isSettlement);
742743

743744
using (var m = new ProfileMarker("Runtime.Notify"))
744745
if (isSettlement)
@@ -934,7 +935,8 @@ internal void InfuseToken(RuntimeVM Runtime, IToken token, Address from, BigInte
934935
infusion[index] = new TokenInfusion(infuseToken.Symbol, value + temp.Value);
935936
}
936937

937-
WriteNFT(Runtime, token.Symbol, tokenID, nft.CurrentChain, nft.CurrentOwner, nft.ROM, nft.RAM, nft.SeriesID, nft.Timestamp, infusion, true);
938+
WriteNFT(Runtime, token.Symbol, tokenID, nft.CurrentChain, nft.Creator, nft.CurrentOwner, nft.ROM, nft.RAM,
939+
nft.SeriesID, nft.Timestamp, infusion, true);
938940

939941
Runtime.Notify(EventKind.Infusion, nft.CurrentOwner, new InfusionEventData(token.Symbol, tokenID, infuseToken.Symbol, value, nft.CurrentChain));
940942
}
@@ -1020,7 +1022,8 @@ internal void TransferToken(RuntimeVM Runtime, IToken token, Address source, Add
10201022

10211023
Runtime.Expect(Runtime.InvokeTriggerOnAccount(true, destination, AccountTrigger.OnReceive, source, destination, token.Symbol, tokenID) != TriggerResult.Failure, "account received trigger failed");
10221024

1023-
WriteNFT(Runtime, token.Symbol, tokenID, Runtime.Chain.Name, destination, nft.ROM, nft.RAM, nft.SeriesID, Runtime.Time, nft.Infusion, true);
1025+
WriteNFT(Runtime, token.Symbol, tokenID, Runtime.Chain.Name, nft.Creator, destination, nft.ROM, nft.RAM,
1026+
nft.SeriesID, Runtime.Time, nft.Infusion, true);
10241027

10251028
if (destination.IsSystem && (destination == Runtime.CurrentContext.Address || isInfusion))
10261029
{
@@ -1220,7 +1223,9 @@ internal void DestroyNFT(RuntimeVM Runtime, string symbol, BigInteger tokenID, A
12201223
Runtime.CallNativeContext(NativeContractKind.Storage, nameof(StorageContract.DeleteData), contractAddress, tokenKey);
12211224
}
12221225

1223-
internal void WriteNFT(RuntimeVM Runtime, string symbol, BigInteger tokenID, string chainName, Address owner, byte[] rom, byte[] ram, BigInteger seriesID, Timestamp timestamp, IEnumerable<TokenInfusion> infusion, bool mustExist)
1226+
internal void WriteNFT(RuntimeVM Runtime, string symbol, BigInteger tokenID, string chainName, Address creator,
1227+
Address owner, byte[] rom, byte[] ram, BigInteger seriesID, Timestamp timestamp,
1228+
IEnumerable<TokenInfusion> infusion, bool mustExist)
12241229
{
12251230
Runtime.Expect(ram != null && ram.Length < TokenContent.MaxRAMSize, "invalid nft ram update");
12261231

@@ -1260,7 +1265,17 @@ internal void WriteNFT(RuntimeVM Runtime, string symbol, BigInteger tokenID, str
12601265
else
12611266
{
12621267
Runtime.Expect(!mustExist, $"nft {symbol} {tokenID} does not exist");
1263-
var genID = GenerateNFT(Runtime, symbol, chainName, owner, rom, ram, seriesID);
1268+
Address _creator;
1269+
if (this.GetProtocolVersion(Runtime.RootStorage) >= 7)
1270+
{
1271+
_creator = creator;
1272+
}
1273+
else
1274+
{
1275+
_creator = owner;
1276+
}
1277+
1278+
var genID = GenerateNFT(Runtime, symbol, chainName, _creator, rom, ram, seriesID);
12641279
Runtime.Expect(genID == tokenID, "failed to regenerate NFT");
12651280
}
12661281
}

Phantasma.Blockchain/Runtime.cs

+13-2
Original file line numberDiff line numberDiff line change
@@ -1352,9 +1352,19 @@ public BigInteger MintToken(string symbol, Address from, Address target, byte[]
13521352
Runtime.Expect(rom.Length <= TokenContent.MaxROMSize, "ROM size exceeds maximum allowed, received: " + rom.Length + ", maximum: " + TokenContent.MaxROMSize);
13531353
Runtime.Expect(ram.Length <= TokenContent.MaxRAMSize, "RAM size exceeds maximum allowed, received: " + ram.Length + ", maximum: " + TokenContent.MaxRAMSize);
13541354

1355+
Address creator;
1356+
if (ProtocolVersion >= 7)
1357+
{
1358+
creator = from;
1359+
}
1360+
else
1361+
{
1362+
creator = target;
1363+
}
1364+
13551365
BigInteger tokenID;
13561366
using (var m = new ProfileMarker("Nexus.CreateNFT"))
1357-
tokenID = Nexus.GenerateNFT(this, symbol, Runtime.Chain.Name, target, rom, ram, seriesID);
1367+
tokenID = Nexus.GenerateNFT(this, symbol, Runtime.Chain.Name, creator, rom, ram, seriesID);
13581368
Runtime.Expect(tokenID > 0, "invalid tokenID");
13591369

13601370
using (var m = new ProfileMarker("Nexus.MintToken"))
@@ -1580,7 +1590,8 @@ public void WriteToken(Address from, string tokenSymbol, BigInteger tokenID, byt
15801590
Runtime.Expect(Runtime.InvokeTriggerOnToken(true, token, TokenTrigger.OnWrite, from, ram, tokenID) != TriggerResult.Failure, "token write trigger failed");
15811591
}
15821592

1583-
Nexus.WriteNFT(this, tokenSymbol, tokenID, nft.CurrentChain, nft.CurrentOwner, nft.ROM, ram, nft.SeriesID, nft.Timestamp, nft.Infusion, true);
1593+
Nexus.WriteNFT(this, tokenSymbol, tokenID, nft.CurrentChain, nft.Creator, nft.CurrentOwner, nft.ROM, ram,
1594+
nft.SeriesID, nft.Timestamp, nft.Infusion, true);
15841595
}
15851596

15861597
public TokenContent ReadToken(string tokenSymbol, BigInteger tokenID)

Phantasma.Domain/DomainSettings.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public StakeReward(Address staker, Timestamp date)
5656

5757
public static class DomainSettings
5858
{
59-
public const int LatestKnownProtocol = 6;
59+
public const int LatestKnownProtocol = 7;
6060

6161
public const int MaxTxPerBlock = 1024;
6262

Phantasma.Domain/IToken.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public struct TokenContent : ISerializable
8686
public static readonly int MaxROMSize = 1024;
8787
public static readonly int MaxRAMSize = 1024;
8888

89-
public TokenContent(BigInteger seriesID, BigInteger mintID, string currentChain, Address creator, Address currentOwner, byte[] ROM, byte[] RAM, Timestamp timestamp, IEnumerable<TokenInfusion> infusion, TokenSeriesMode mode) : this()
89+
public TokenContent(BigInteger seriesID, BigInteger mintID, string currentChain, Address creator, Address currentOwner,
90+
byte[] ROM, byte[] RAM, Timestamp timestamp, IEnumerable<TokenInfusion> infusion, TokenSeriesMode mode) : this()
9091
{
9192
this.SeriesID = seriesID;
9293
this.MintID = mintID;

Phantasma.P2P/Messages/ListMessage.cs

+55
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ public static ChainInfo Unserialize(BinaryReader reader)
3939
}
4040
}
4141

42+
public class PeerInfo
43+
{
44+
public string version;
45+
public PeerCaps caps;
46+
public BigInteger minimumFee;
47+
public uint minimumPow;
48+
public PeerPort[] ports;
49+
}
50+
4251
public struct BlockRange
4352
{
4453
public readonly Block[] blocks;
@@ -64,6 +73,8 @@ public class ListMessage : Message
6473
private ChainInfo[] _chains = null;
6574
public IEnumerable<ChainInfo> Chains => _chains;
6675

76+
public PeerInfo _peerInfo = null;
77+
6778
public const int MaxPeers = 255;
6879
public const int MaxChains = 128;
6980
public const int MaxTransactions = 1024; // for mempool
@@ -169,6 +180,22 @@ internal static ListMessage FromReader(Address address, string host, BinaryReade
169180
}
170181
}
171182

183+
if (kind.HasFlag(RequestKind.Info))
184+
{
185+
var version = reader.ReadVarString();
186+
var caps = (PeerCaps)reader.ReadInt32();
187+
var minimumFee = reader.ReadBigInteger();
188+
var minimumPow = (int)reader.ReadVarInt();
189+
var portCount = (int)reader.ReadVarInt();
190+
var ports = new PeerPort[portCount];
191+
for (int i=0; i<portCount; i++)
192+
{
193+
var portName = reader.ReadVarString();
194+
var portNumber = (int)reader.ReadVarInt();
195+
ports[i] = new PeerPort(portName, portNumber);
196+
}
197+
}
198+
172199
return result;
173200
}
174201

@@ -233,6 +260,20 @@ protected override void OnSerialize(BinaryWriter writer)
233260
}
234261
}
235262
}
263+
264+
if (Kind.HasFlag(RequestKind.Info))
265+
{
266+
writer.WriteVarString(_peerInfo.version);
267+
writer.Write((int)_peerInfo.caps);
268+
writer.WriteBigInteger(_peerInfo.minimumFee);
269+
writer.WriteVarInt(_peerInfo.minimumPow);
270+
writer.WriteVarInt(_peerInfo.ports.Length);
271+
foreach (var entry in _peerInfo.ports)
272+
{
273+
writer.WriteVarString(entry.Name);
274+
writer.WriteVarInt(entry.Port);
275+
}
276+
}
236277
}
237278

238279
public override IEnumerable<string> GetDescription()
@@ -312,5 +353,19 @@ public void AddBlockRange(Chain chain, BigInteger startHeight, uint count)
312353

313354
AddBlockRange(chain.Name, blocks.ToArray(), transactions);
314355
}
356+
357+
public void SetInfo(string version, PeerCaps caps, BigInteger minimumFee, uint minimumPow, IEnumerable<PeerPort> ports)
358+
{
359+
var info = new PeerInfo()
360+
{
361+
version = version,
362+
caps = caps,
363+
minimumFee = minimumFee,
364+
minimumPow = minimumPow,
365+
ports = ports.ToArray()
366+
};
367+
368+
this._peerInfo = info;
369+
}
315370
}
316371
}

Phantasma.P2P/Messages/RequestMessage.cs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public enum RequestKind
1717
Mempool = 0x4,
1818
Blocks = 0x8,
1919
Transactions = 0x16,
20+
Info = 0x32,
2021
}
2122

2223
public struct RequestRange

0 commit comments

Comments
 (0)