static KeyPair CreateRandomAccount(Account source, long nativeAmount)
        {
            var master = KeyPair.Master();
            var dest = KeyPair.Random();

            var operation =
                new CreateAccountOperation.Builder(dest, nativeAmount)
                .SetSourceAccount(source.KeyPair)
                .Build();

            source.IncrementSequenceNumber();

            Stellar.Transaction transaction =
                new Stellar.Transaction.Builder(source)
                .AddOperation(operation)
                .Build();

            transaction.Sign(source.KeyPair);

            string message = transaction.ToEnvelopeXdrBase64();

            string response = GetResult(message);

            Console.WriteLine(response);
            Console.WriteLine(dest.AccountId);
            Console.WriteLine(dest.Seed);

            return dest;
        }
예제 #2
0
        public static Operation FromXdr(Generated.Operation xdr)
        {
            var       body      = xdr.Body;
            Operation operation = null;

            switch (body.Discriminant.InnerValue)
            {
            case Generated.OperationType.OperationTypeEnum.CREATE_ACCOUNT:
                operation = new CreateAccountOperation.Builder(body.CreateAccountOp).Build();
                break;

            case Generated.OperationType.OperationTypeEnum.PAYMENT:
                operation = new PaymentOperation.Builder(body.PaymentOp).Build();
                break;

            case Generated.OperationType.OperationTypeEnum.PATH_PAYMENT:
                //operation = new PathPaymentOperation.Builder(body.getPathPaymentOp()).build();
                break;

            case Generated.OperationType.OperationTypeEnum.MANAGE_OFFER:
                //operation = new ManagerOfferOperation.Builder(body.getManageOfferOp()).build();
                break;

            case Generated.OperationType.OperationTypeEnum.CREATE_PASSIVE_OFFER:
                //operation = new CreatePassiveOfferOperation.Builder(body.getCreatePassiveOfferOp()).build();
                break;

            case Generated.OperationType.OperationTypeEnum.SET_OPTIONS:
                //operation = new SetOptionsOperation.Builder(body.getSetOptionsOp()).build();
                break;

            case Generated.OperationType.OperationTypeEnum.CHANGE_TRUST:
                operation = new ChangeTrustOperation.Builder(body.ChangeTrustOp).Build();
                break;

            case Generated.OperationType.OperationTypeEnum.ALLOW_TRUST:
                //operation = new AllowTrustOperation.Builder(body.getAllowTrustOp()).build();
                break;

            case Generated.OperationType.OperationTypeEnum.ACCOUNT_MERGE:
                //operation = new AccountMergeOperation.Builder(body).build();
                break;

            default:
                throw new Exception("Unknown operation body " + body.Discriminant.InnerValue);
            }
            if (xdr.SourceAccount != null)
            {
                operation.SourceAccount = KeyPair.FromXdrPublicKey(xdr.SourceAccount.InnerValue);
            }
            return(operation);
        }
        public Stellar.Transaction SampleTransaction(string destAccountId)
        {
            Stellar.Network.CurrentNetwork = "";

            var master = KeyPair.Master();
            var dest = string.IsNullOrEmpty(destAccountId) ? KeyPair.Random() : KeyPair.FromAccountId(destAccountId);

            var sourceAccount = new Account(master, 1);

            CreateAccountOperation operation =
                new CreateAccountOperation.Builder(dest, 1000)
                //.SetSourceAccount(master)
                .Build();

            Stellar.Transaction transaction =
                new Stellar.Transaction.Builder(sourceAccount)
                .AddOperation(operation)
                .Build();

            return transaction;
        }