public void LockTokens(Address from, string symbol, BigInteger amount, uint duration) { Runtime.Expect(amount > 0, "amount must be greater than zero"); Runtime.Expect(duration >= 86400, "minimum duration should be one day"); // minimum 1 day Runtime.Expect(IsWitness(from), "invalid witness"); Runtime.Expect(Runtime.Nexus.TokenExists(symbol), "invalid token"); var tokenInfo = this.Runtime.Nexus.GetTokenInfo(symbol); Runtime.Expect(tokenInfo.Flags.HasFlag(TokenFlags.Fungible), "token must be fungible"); Runtime.Expect(Runtime.Nexus.TransferTokens(Runtime, symbol, from, this.Address, amount), "transfer failed"); var list = _entries.Get <Address, StorageList>(from); var entry = new VaultEntry() { amount = amount, unlockTime = Runtime.Time + TimeSpan.FromSeconds(duration), }; list.Add(entry); Runtime.Notify(EventKind.TokenEscrow, from, new TokenEventData() { symbol = symbol, value = amount, chainAddress = Runtime.Chain.Address }); }
public void LockTokens(Address from, string symbol, BigInteger amount, uint duration) { Runtime.Expect(amount > 0, "amount must be greater than zero"); Runtime.Expect(duration >= 86400, "minimum duration should be one day"); // minimum 1 day Runtime.Expect(IsWitness(from), "invalid witness"); var token = this.Runtime.Nexus.FindTokenBySymbol(symbol); Runtime.Expect(token != null, "invalid token"); Runtime.Expect(token.Flags.HasFlag(TokenFlags.Fungible), "token must be fungible"); var balances = this.Runtime.Chain.GetTokenBalances(token); Runtime.Expect(token.Transfer(balances, from, Runtime.Chain.Address, amount), "transfer failed"); List <VaultEntry> list; if (_entries.ContainsKey(from)) { list = _entries[from]; } else { list = new List <VaultEntry>(); _entries[from] = list; } var entry = new VaultEntry() { amount = amount, unlockTime = Runtime.Block.Timestamp.Value + duration, }; list.Add(entry); }
public void LockTokens(Address from, string symbol, BigInteger amount, uint duration) { Runtime.Expect(amount > 0, "amount must be greater than zero"); Runtime.Expect(duration >= 86400, "minimum duration should be one day"); // minimum 1 day Runtime.Expect(IsWitness(from), "invalid witness"); Runtime.Expect(Runtime.Nexus.TokenExists(symbol), "invalid token"); var tokenInfo = this.Runtime.Nexus.GetTokenInfo(symbol); Runtime.Expect(tokenInfo.Flags.HasFlag(TokenFlags.Fungible), "token must be fungible"); Runtime.Expect(Runtime.Nexus.TransferTokens(Runtime, symbol, from, Runtime.Chain.Address, amount), "transfer failed"); List <VaultEntry> list; if (_entries.ContainsKey(from)) { list = _entries[from]; } else { list = new List <VaultEntry>(); _entries[from] = list; } var entry = new VaultEntry() { amount = amount, unlockTime = Runtime.Time + TimeSpan.FromSeconds(duration), }; list.Add(entry); }