public Transaction GenerateNftSale(KeyPair source, Chain chain, string tokenSymbol, BigInteger tokenId, BigInteger price) { Timestamp endDate = this.CurrentTime + TimeSpan.FromDays(5); var script = ScriptUtils.BeginScript().AllowGas(source.Address, Address.Null, MinimumFee, 9999).CallContract("market", "SellToken", source.Address, tokenSymbol, DomainSettings.FuelTokenSymbol, tokenId, price, endDate).SpendGas(source.Address).EndScript(); var tx = MakeTransaction(source, ProofOfWork.None, chain, script); return(tx); }
public Transaction GenerateSetTokenMetadata(KeyPair source, string tokenSymbol, string key, string value) { var chain = Nexus.RootChain; var script = ScriptUtils.BeginScript().AllowGas(source.Address, Address.Null, MinimumFee, 9999).CallInterop("Runtime.SetMetadata", source.Address, tokenSymbol, key, value).SpendGas(source.Address).EndScript(); var tx = MakeTransaction(source, ProofOfWork.None, chain, script); return(tx); }
public Transaction GenerateSetTokenMetadata(KeyPair source, Token token, string key, byte[] value) { var chain = Nexus.RootChain; var script = ScriptUtils.BeginScript().AllowGas(source.Address, Address.Null, 1, 9999).CallContract("nexus", "SetTokenMetadata", token.Symbol, key, value).SpendGas(source.Address).EndScript(); var tx = MakeTransaction(source, chain, script); return(tx); }
public Transaction GenerateNftSidechainTransfer(KeyPair source, Address destAddress, Chain sourceChain, Chain destChain, string tokenSymbol, BigInteger tokenId) { var script = ScriptUtils.BeginScript().AllowGas(source.Address, Address.Null, MinimumFee, 9999).CallInterop("Runtime.SendToken", destChain.Address, source.Address, destAddress, tokenSymbol, tokenId).SpendGas(source.Address).EndScript(); var tx = MakeTransaction(source, ProofOfWork.None, sourceChain, script); return(tx); }
public Transaction GenerateNftSidechainTransfer(KeyPair source, Address destAddress, Chain sourceChain, Chain destChain, Token token, BigInteger tokenId) { var script = ScriptUtils.BeginScript().AllowGas(source.Address, Address.Null, 1, 9999).CallContract("token", "SendToken", destChain.Address, source.Address, destAddress, token.Symbol, tokenId).SpendGas(source.Address).EndScript(); var tx = MakeTransaction(source, sourceChain, script); return(tx); }
public Transaction GenerateStableClaim(KeyPair source, Chain sourceChain, BigInteger amount) { var script = ScriptUtils.BeginScript().AllowGas(source.Address, Address.Null, 1, 9999).CallContract("bank", "Claim", source.Address, amount).SpendGas(source.Address).EndScript(); var tx = MakeTransaction(source, sourceChain, script); tx.Sign(source); return(tx); }
public Transaction GenerateNftSale(KeyPair source, Chain chain, Token token, BigInteger tokenId, BigInteger price) { var endDate = new Timestamp(Timestamp.Now + TimeSpan.FromDays(5)); var script = ScriptUtils.BeginScript().AllowGas(source.Address, Address.Null, 1, 9999).CallContract("market", "SellToken", source.Address, token.Symbol, Nexus.FuelTokenSymbol, tokenId, price, endDate).SpendGas(source.Address).EndScript(); var tx = MakeTransaction(source, chain, script); return(tx); }
public Transaction GenerateAccountRegistration(PhantasmaKeys source, string name) { var sourceChain = this.Nexus.RootChain; var script = ScriptUtils.BeginScript().AllowGas(source.Address, Address.Null, MinimumFee, 9999).CallContract(NativeContractKind.Account, nameof(AccountContract.RegisterName), source.Address, name).SpendGas(source.Address).EndScript(); var tx = MakeTransaction(source, ProofOfWork.Minimal, sourceChain, script); pendingNames.Add(source.Address); return(tx); }
private void TopUpChannel(NexusSimulator simulator, PhantasmaKeys from, BigInteger amount) { simulator.BeginBlock(); simulator.GenerateCustomTransaction(from, ProofOfWork.None, () => ScriptUtils.BeginScript().AllowGas(from.Address, Address.Null, 1, 9999) .CallContract("relay", "TopUpChannel", from.Address, amount). SpendGas(from.Address).EndScript()); simulator.EndBlock(); }
public Transaction GenerateAccountRegistration(KeyPair source, string name) { var sourceChain = this.Nexus.RootChain; var script = ScriptUtils.BeginScript().AllowGas(source.Address, Address.Null, 1, 9999).CallContract("account", "Register", source.Address, name).SpendGas(source.Address).EndScript(); var tx = MakeTransaction(source, sourceChain, script); pendingNames.Add(source.Address); return(tx); }
static int GetByteSize(string str) { if (ScriptUtils.IsKatakana(str)) { return(str.Length); } return(GetByteCount(str)); }
static void Main(string[] args) { InitializeLanguage(); InitializeLibraries(); string fileName = null; int i = 0; string configDir = GeneralUtils.GetConfigDirectory(true); if (configDir == null) { MessageBox.Show(String.Format(Properties.Resources.Program_ErrorCreatingUserDirectory, GeneralUtils.GetConfigDirectory(false)), Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } for (i = 0; i < args.Length; ++i) { if (args[i].StartsWith("-")) { if (args[i].StartsWith("-ext:")) { CANAPEExtensionManager.LoadExtension(args[i].Substring("-ext:".Length)); } } else { break; } } if (i < args.Length) { fileName = args[i]; } if (Properties.Settings.Default.RunOnce == false) { Properties.Settings.Default.RunOnce = true; Program.SaveSettings(); } if (!Debugger.IsAttached) { Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm(fileName)); ScriptUtils.DeleteTempFiles(); }
public Transaction GenerateSwap(PhantasmaKeys source, Chain chain, string fromSymbol, string toSymbol, BigInteger amount) { var script = ScriptUtils.BeginScript(). CallContract("swap", "SwapTokens", source.Address, fromSymbol, toSymbol, amount). AllowGas(source.Address, Address.Null, MinimumFee, 9999). SpendGas(source.Address). EndScript(); var tx = MakeTransaction(source, ProofOfWork.None, chain, script); return tx; }
protected void OnSetValue(string[] args) { var chain = _cli.Nexus.GetChainByName(_cli.Nexus.RootChain.Name); var fuelToken = _cli.Nexus.GetTokenInfo(_cli.Nexus.RootStorage, DomainSettings.FuelTokenSymbol); var balance = chain.GetTokenBalance(chain.Storage, fuelToken, _cli.NodeKeys.Address); if (balance == 0) { Console.WriteLine("Node wallet needs gas to create a platform token!"); return; } var key = args[0]; if (string.IsNullOrEmpty(key)) { Console.WriteLine("Key has to be set!"); return; } Phantasma.Numerics.BigInteger value; try { value = Phantasma.Numerics.BigInteger.Parse(args[1]); } catch { Console.WriteLine("Value has to be set!"); return; } var script = ScriptUtils.BeginScript() .AllowGas(_cli.NodeKeys.Address, Address.Null, 100000, 15000) .CallContract("governance", "SetValue", key, value) .SpendGas(_cli.NodeKeys.Address).EndScript(); var expire = Timestamp.Now + TimeSpan.FromMinutes(2); var tx = new Phantasma.Blockchain.Transaction(_cli.Nexus.Name, _cli.Nexus.RootChain.Name, script, expire, Spook.TxIdentifier); tx.Mine((int)ProofOfWork.Minimal); tx.Sign(_cli.NodeKeys); if (_cli.Mempool != null) { _cli.Mempool.Submit(tx); Console.WriteLine($"Transaction {tx.Hash} submitted to mempool."); } else { Console.WriteLine("No mempool available"); return; } Console.WriteLine($"SetValue {key}:{value} ts: {tx.Hash}"); }
public Transaction GenerateSideChainSettlement(PhantasmaKeys source, Chain sourceChain, Chain destChain, Transaction transaction) { var script = ScriptUtils. BeginScript(). CallContract(Nexus.BlockContractName, "SettleTransaction", sourceChain.Address, transaction.Hash). AllowGas(source.Address, Address.Null, MinimumFee, 800). SpendGas(source.Address). EndScript(); var tx = MakeTransaction(source, ProofOfWork.None, destChain, script); return tx; }
public Transaction GenerateTransfer(KeyPair source, Address dest, Chain chain, string tokenSymbol, BigInteger amount) { var script = ScriptUtils.BeginScript(). AllowGas(source.Address, Address.Null, 1, 9999). CallContract("token", "TransferTokens", source.Address, dest, tokenSymbol, amount). SpendGas(source.Address). EndScript(); var tx = MakeTransaction(source, chain, script); return(tx); }
public void BlockSerialization() { var keysA = KeyPair.Generate(); var txs = new List <Transaction>(); var symbol = DomainSettings.FuelTokenSymbol; int count = 5; var amounts = new BigInteger[count]; for (int i = 0; i < count; i++) { var keysB = KeyPair.Generate(); amounts[i] = UnitConversion.ToBigInteger(20 + (i + 1), DomainSettings.FuelTokenDecimals); var script = ScriptUtils.BeginScript(). AllowGas(keysA.Address, Address.Null, 1, 9999). TransferTokens(symbol, keysA.Address, keysB.Address, amounts[i]). SpendGas(keysA.Address). EndScript(); var tx = new Transaction("simnet", "main", script, Timestamp.Now - TimeSpan.FromMinutes(i)); txs.Add(tx); } var chainKeys = KeyPair.Generate(); var hashes = txs.Select(x => x.Hash); uint protocol = 42; var block = new Block(1, chainKeys.Address, Timestamp.Now, hashes, Hash.Null, protocol); int index = 0; foreach (var hash in hashes) { var data = new TokenEventData() { symbol = symbol, chainAddress = keysA.Address, value = amounts[index] }; var dataBytes = Serialization.Serialize(data); block.Notify(hash, new Event(EventKind.TokenSend, keysA.Address, "test", dataBytes)); index++; } var bytes = block.ToByteArray(); Assert.IsTrue(bytes != null); var block2 = Block.Unserialize(bytes); Assert.IsTrue(block2 != null); Assert.IsTrue(block.Hash == block2.Hash); }
public Transaction GenerateSwap(KeyPair source, Chain chain, string fromSymbol, string toSymbol, BigInteger amount) { var script = ScriptUtils.BeginScript(). CallContract("swap", "SwapTokens", source.Address, fromSymbol, toSymbol, amount). AllowGas(source.Address, Address.Null, 1, 9999). SpendGas(source.Address). EndScript(); var tx = MakeTransaction(source, chain, script); return(tx); }
public Transaction GenerateChain(KeyPair source, Chain parentchain, string name, params string[] contracts) { var script = ScriptUtils.BeginScript(). AllowGas(source.Address, Address.Null, 1, 9999). CallContract("nexus", "CreateChain", source.Address, name, parentchain.Name, contracts). SpendGas(source.Address). EndScript(); var tx = MakeTransaction(source, Nexus.RootChain, script); return(tx); }
public void TimeSkipToDate(DateTime date) { CurrentTime = date; BeginBlock(); var tx = GenerateCustomTransaction(_owner, ProofOfWork.None, () => ScriptUtils.BeginScript().AllowGas(_owner.Address, Address.Null, MinimumFee, 9999) .CallContract(Nexus.StakeContractName, "GetUnclaimed", _owner.Address). SpendGas(_owner.Address).EndScript()); EndBlock(); }
public void TransferScriptMethodExtraction() { var source = PhantasmaKeys.Generate(); var dest = PhantasmaKeys.Generate(); var amount = UnitConversion.GetUnitValue(DomainSettings.StakingTokenDecimals); var script = ScriptUtils.BeginScript().AllowGas(source.Address, Address.Null, 1, 999).TransferTokens(DomainSettings.StakingTokenSymbol, source.Address, dest.Address, amount).SpendGas(source.Address).EndScript(); var table = DisasmUtils.GetDefaultDisasmTable(); var methods = DisasmUtils.ExtractMethodCalls(script, table); Assert.IsTrue(methods != null && methods.Count() == 3); }
public dynamic Invoke(object target, string name, object[] args) { object[] invokeArgs = args; if (name == null) { invokeArgs = new object[args.Length + 1]; invokeArgs[0] = target; Array.Copy(args, 0, invokeArgs, 1, args.Length); } return(ScriptUtils.Invoke(_script, null, name, invokeArgs)); }
public override bool Install(ScriptBuild Build) { string SourceBinariesDirectory = Path.Combine(Build.Directory, "Binaries"); string TargetBinariesDirectory = Path.Combine(Build.InstallLocation, "Binaries"); if (!ScriptUtils.CreateJunction(SourceBinariesDirectory, TargetBinariesDirectory)) { return(false); } return(true); }
static public bool Evaluate(this CompareOperator inComparison, string inCheck, string inValue) { inCheck = inCheck ?? string.Empty; inValue = inValue ?? string.Empty; switch (inComparison) { case CompareOperator.EqualTo: return(inCheck == inValue); case CompareOperator.NotEqualTo: return(inCheck != inValue); case CompareOperator.True: return(!string.IsNullOrEmpty(inCheck)); case CompareOperator.False: return(string.IsNullOrEmpty(inCheck)); case CompareOperator.Contains: return(inCheck.Contains(inValue)); case CompareOperator.StartsWith: return(inCheck.StartsWith(inValue)); case CompareOperator.EndsWith: return(inCheck.EndsWith(inValue)); case CompareOperator.DoesNotContain: return(!inCheck.Contains(inValue)); case CompareOperator.DoesNotStartWith: return(!inCheck.StartsWith(inValue)); case CompareOperator.DoesNotEndWith: return(!inCheck.EndsWith(inValue)); case CompareOperator.IsEmpty: return(string.IsNullOrEmpty(inValue)); case CompareOperator.IsNotEmpty: return(!string.IsNullOrEmpty(inValue)); case CompareOperator.Matches: return(ScriptUtils.StringMatch(inCheck, inValue)); case CompareOperator.DoesNotMatch: return(!ScriptUtils.StringMatch(inCheck, inValue)); default: throw InvalidComparisonException(inComparison); } }
// ----------------------------------------------------------------- /// <summary> /// /// </summary> // ----------------------------------------------------------------- private void DoJsonReadNotecard( UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier) { UUID assetID; if (!UUID.TryParse(notecardIdentifier, out assetID)) { SceneObjectPart part = m_scene.GetSceneObjectPart(hostID); assetID = ScriptUtils.GetAssetIdFromItemName(part, notecardIdentifier, (int)AssetType.Notecard); } AssetBase a = m_scene.AssetService.Get(assetID.ToString()); if (a == null) { GenerateRuntimeError(String.Format("Unable to find notecard asset {0}", assetID)); } if (a.Type != (sbyte)AssetType.Notecard) { GenerateRuntimeError(String.Format("Invalid notecard asset {0}", assetID)); } m_log.DebugFormat("[JsonStoreScripts]: read notecard in context {0}", storeID); try { int result; string[] data = SLUtil.ParseNotecardToArray(a.Data); if (data.Length == 0) { result = m_store.SetValue(storeID, path, string.Empty, true) ? 1 : 0; } else { StringBuilder sb = new StringBuilder(256); for (int i = 0; i < data.Length; ++i) { sb.AppendLine(data[i]); } result = m_store.SetValue(storeID, path, sb.ToString(), true) ? 1 : 0; } m_comms.DispatchReply(scriptID, result, "", reqID.ToString()); return; } catch (Exception e) { m_log.WarnFormat("[JsonStoreScripts]: Json parsing failed; {0}", e.Message); } GenerateRuntimeError(String.Format("Json parsing failed for {0}", assetID)); m_comms.DispatchReply(scriptID, 0, "", reqID.ToString()); }
public Transaction GenerateChain(PhantasmaKeys source, string organization, string parentchain, string name) { Throw.IfNull(parentchain, nameof(parentchain)); var script = ScriptUtils.BeginScript(). AllowGas(source.Address, Address.Null, MinimumFee, 9999). CallInterop("Nexus.CreateChain", source.Address, organization, name, parentchain). SpendGas(source.Address).EndScript(); var tx = MakeTransaction(source, ProofOfWork.Minimal, Nexus.RootChain, script); return(tx); }
private void ApplyScript_Click(ScriptDocument script) { try { ApplyStringConverter(ScriptUtils.GetInstance <IStringConverter>(script.Container) ?? new ScriptStringConverter(script)); } catch (Exception ex) { MessageBox.Show(this, ex.Message, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public Transaction MintNonFungibleToken(PhantasmaKeys owner, Address destination, string tokenSymbol, byte[] rom, byte[] ram) { var chain = Nexus.RootChain; var script = ScriptUtils. BeginScript(). AllowGas(owner.Address, Address.Null, MinimumFee, 9999). CallInterop("Runtime.MintToken", owner.Address, destination, tokenSymbol, rom, ram). SpendGas(owner.Address). EndScript(); var tx = MakeTransaction(owner, ProofOfWork.None, chain, script); return tx; }
public void TimeSkipToDate(DateTime date) { CurrentTime = date; DateTime.SpecifyKind(CurrentTime, DateTimeKind.Utc); BeginBlock(); var tx = GenerateCustomTransaction(_owner, ProofOfWork.None, () => ScriptUtils.BeginScript().AllowGas(_owner.Address, Address.Null, MinimumFee, 9999) .CallContract(NativeContractKind.Stake, nameof(StakeContract.GetUnclaimed), _owner.Address). SpendGas(_owner.Address).EndScript()); EndBlock(); }
public void TimeSkipYears(int years) { CurrentTime = CurrentTime.AddYears(years); BeginBlock(); var tx = GenerateCustomTransaction(_owner, ProofOfWork.None, () => ScriptUtils.BeginScript().AllowGas(_owner.Address, Address.Null, MinimumFee, 9999) .CallContract(Nexus.StakeContractName, "GetUnclaimed", _owner.Address). SpendGas(_owner.Address).EndScript()); EndBlock(); var txCost = Nexus.RootChain.GetTransactionFee(tx); }