Exemplo n.º 1
0
        public static Hash SendTransfer(JSONRPC_Client rpc, Logger logger, string nexusName, string host, PhantasmaKeys from, Address to, BigInteger amount)
        {
            Throw.IfNull(rpc, nameof(rpc));
            Throw.IfNull(logger, nameof(logger));

            var script = ScriptUtils.BeginScript().AllowGas(from.Address, Address.Null, 1, 9999).TransferTokens("SOUL", from.Address, to, amount).SpendGas(from.Address).EndScript();

            var tx = new Phantasma.Blockchain.Transaction(nexusName, "main", script, Timestamp.Now + TimeSpan.FromMinutes(30));

            tx.Sign(from);

            var bytes = tx.ToByteArray(true);

            //log.Debug("RAW: " + Base16.Encode(bytes));

            var response = rpc.SendRequest(logger, host, "sendRawTransaction", Base16.Encode(bytes));

            if (response == null)
            {
                logger.Error($"Error sending {amount} {DomainSettings.FuelTokenSymbol} from {from.Address} to {to}...");
                return(Hash.Null);
            }

            if (response.HasNode("error"))
            {
                var error = response.GetString("error");
                logger.Error("Error: " + error);
                return(Hash.Null);
            }

            var hash = response.Value;

            return(Hash.Parse(hash));
        }
Exemplo n.º 2
0
        public bool IsWitness(Transaction transaction)
        {
            var size = this.Size;

            if (size < 1)
            {
                return(false);
            }

            var majorityCount = (size / 2) + 1;

            if (transaction == null || transaction.Signatures.Length < majorityCount)
            {
                return(false);
            }

            int witnessCount = 0;

            var members = new List <Address>(this.GetMembers());
            var msg     = transaction.ToByteArray(false);

            foreach (var sig in transaction.Signatures)
            {
                if (witnessCount >= majorityCount)
                {
                    break; // dont waste time if we already reached a majority
                }

                //ring signature not supported yet here
                if (sig.Kind == SignatureKind.Ring)
                {
                    continue;
                }

                foreach (var addr in members)
                {
                    if (sig.Verify(msg, addr))
                    {
                        witnessCount++;
                        members.Remove(addr);
                        break;
                    }
                }
            }

            return(witnessCount >= majorityCount);
        }