public static FundingTransaction Create( UserModel from, int entityId, EntityType entityType, decimal amount, CurrencyType currencyType, string note = null ) { return(Find(FundingTransaction.Create(from, entityId, entityType, null, amount, currencyType))); }
public FundingCreatedMessage Handle(AcceptChannelMessage acceptMessage, PendingChannel pendingChannel) { var oldState = LocalChannelState.AcceptChannel; var openMessage = pendingChannel.OpenMessage; _channelLoggingService.LogPendingChannelInfo(openMessage.TemporaryChannelId.ToHex(), oldState, "Remote accepted channel open"); FundingTransaction fundingTx = _fundingService.CreateFundingTransaction(openMessage.FundingSatoshis, openMessage.FeeratePerKw, openMessage.FundingPubKey, acceptMessage.FundingPubKey); var channel = CreateChannel(pendingChannel.ChannelIndex, fundingTx, openMessage, acceptMessage); channel.IsFunder = true; _commitmentService.CreateInitialCommitmentTransactions(openMessage, acceptMessage, channel, pendingChannel.RevocationKey); channel.State = LocalChannelState.FundingCreated; var signatureOfRemoteCommitmentTx = channel.RemoteCommitmentTxParameters.LocalSignature; FundingCreatedMessage fundingCreatedMessage = new FundingCreatedMessage { TemporaryChannelId = openMessage.TemporaryChannelId, FundingTransactionId = fundingTx.Transaction.GetHash().ToBytes(), FundingOutputIndex = fundingTx.FundingOutputIndex, Signature = signatureOfRemoteCommitmentTx.ToRawSignature() }; pendingChannel.Channel = channel; _channelLoggingService.LogStateUpdate(channel, oldState, additionalData: fundingTx.Transaction.ToString()); return(fundingCreatedMessage); }
public static void CreateTxFromInvoice(Invoice invoice) { FundingTransaction.Create( UserRepository.Find(invoice.user_id), invoice.entity_id, invoice.entity_type, invoice, invoice.amount, invoice.currency_type ); }
public static FundingTransaction CreateDeposit( UserModel from, Invoice invoice ) { if (invoice.entity_type != EntityType.UserBalance) { throw new Exception("Deposit can be done only for UserBalance, tried for " + invoice.entity_type); } return(Find(FundingTransaction.Create( from, invoice.entity_id, invoice.entity_type, invoice, invoice.amount, invoice.currency_type ))); }
public void GetLatest_DataCorrect_GotTransactions() { var amount = 10; var entityId = Rand.Int(); var txs = FundingTransactionFaker.CreateMany(amount, entityId).Take(amount).ToList(); var result = FundingTransaction.GetLatest(entityId, EntityType.Project, amount); foreach (var item in result) { Assert.NotNull(txs.FirstOrDefault(x => x.guid == item.guid)); } }
private LocalChannel CreateChannel(uint index, FundingTransaction fundingTx, OpenChannelMessage openMessage, AcceptChannelMessage acceptMessage) { LocalChannel channel = new LocalChannel(); channel.ChannelIndex = index; channel.TemporaryChannelId = openMessage.TemporaryChannelId.ToHex(); channel.LocalChannelParameters = ChannelParameters.CreateFromOpenMessage(openMessage); channel.RemoteChannelParameters = ChannelParameters.CreateFromAcceptMessage(acceptMessage); channel.FundingSatoshis = openMessage.FundingSatoshis; channel.PushMSat = openMessage.PushMSat; channel.MinimumDepth = acceptMessage.MinimumDepth; channel.FundingTransactionId = fundingTx.Transaction.GetHash().ToString(); channel.FundingOutputIndex = fundingTx.FundingOutputIndex; channel.ChannelId = LocalChannel.DeriveChannelId(fundingTx.Transaction, fundingTx.FundingOutputIndex); channel.FeeRatePerKw = openMessage.FeeratePerKw; return(channel); }
public void Create_DataCorrect_GotCorrectId() { var user = UserFaker.Create(); var project = ProjectFaker.Create(user); var invoice = InvoiceFaker.Create(user); var id = FundingTransaction.Create( user, project.id, EntityType.Project, invoice, 0.05M, CurrencyType.BitCoin ); Assert.True(id > 0); var tx = FundingTransactionRepository.Find(id); Assert.NotNull(tx); }
public static UserModel FindOrCreateByEmailAndLogin( string email, string login, string password = null, UserModel referral = null ) { password ??= Rand.RandomString(); var user = UserModel.FindByEmail(email); var loginUser = UserModel.FindByLogin(login); var baseLogin = login; int postfixNum = 0; while (loginUser != null) { postfixNum++; login = $"{baseLogin}_{postfixNum}"; loginUser = UserModel.FindByLogin(login); } user ??= Create(email, login, password); UserBadge.Create(user, "Early adopter"); int tokenRegisterBonus = System.Convert.ToInt32( AppConfig.GetConfiguration("user:registration:token_bonus") ); if (tokenRegisterBonus > 0) { UserBalance.Create(user, CurrencyType.GitComToken, tokenRegisterBonus); FundingTransaction.Create( user, user.id, EntityType.User, null, tokenRegisterBonus, CurrencyType.GitComToken ); } if (referral != null) { UserReferralRepository.Create(user, referral); } return(user); }
public void CreateFundingTransactionTest() { var keyService = new Mock <IWalletService>(); var blockchainClientService = new Mock <IBlockchainClientService>(); var secret = new BitcoinSecret("cRCH7YNcarfvaiY1GWUKQrRGmoezvfAiqHtdRvxe16shzbd7LDMz"); var fundingKeyPrivateKey = new ECKeyPair(secret.PrivateKey.GetBytes(), true); var pubKeyAddress = fundingKeyPrivateKey.ToPubKey().GetAddress(NBitcoin.Network.TestNet); var inputTx = Transaction.Parse("01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff0100f2052a010000001976a9143ca33c2e4446f4a305f23c80df8ad1afdcf652f988ac00000000", NBitcoin.Network.TestNet); keyService.Setup(k => k.Key).Returns(fundingKeyPrivateKey); keyService.Setup(k => k.PubKeyAddress).Returns(pubKeyAddress); blockchainClientService.Setup(b => b.ListUtxo(1, Int32.MaxValue, pubKeyAddress)) .Returns(new List <Utxo>() { new Utxo() { AmountSatoshi = 100000000, OutPoint = new OutPoint(inputTx, 0), ScriptPubKey = inputTx.Outputs[0].ScriptPubKey } }); FundingService fundingService = new FundingService(new LoggerFactory(), keyService.Object, blockchainClientService.Object, null); fundingService.Initialize(NetworkParameters.BitcoinTestnet); ECKeyPair pubKey1 = new ECKeyPair("023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb", false); ECKeyPair pubKey2 = new ECKeyPair("030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c1", false); FundingTransaction fundingTransaction = fundingService.CreateFundingTransaction(10000000, 1000, pubKey1, pubKey2); Assert.Equal(1, fundingTransaction.FundingOutputIndex); Assert.Single(fundingTransaction.Transaction.Inputs); Assert.Equal(2, fundingTransaction.Transaction.Outputs.Count); Assert.Equal(89999765, fundingTransaction.Transaction.Outputs[0].Value.Satoshi); Assert.Equal(10000000, fundingTransaction.Transaction.Outputs[1].Value.Satoshi); Assert.Equal("35effff7a94b0fbd819b2feec4737d88a9c2f1a7cca481bd6fb206d23029c974", fundingTransaction.Transaction.GetHash().ToString()); }
public static FundingTransaction Find(UserModel user, Invoice invoice, int entityId, EntityType entityType) { return(FundingTransaction.Find(user, invoice, entityId, entityType)); }
public static FundingTransaction Find(int id) => FundingTransaction.Find(id);
public static FundingTransaction[] Get(UserModel user, int limit = 10) { return(FundingTransaction.Get(user, limit)); }
public static FundingTransaction[] Get( int entityId, EntityType entityType, CurrencyType currencyType, int limit = 10 ) { return(FundingTransaction.Get(entityId, entityType, currencyType, limit)); }
public static FundingTransaction Find(Invoice invoice) => FundingTransaction.Find(invoice);
public void HandleTest() { var mocks = new ChannelEstablishmentMocks(); var revocationKey = new ECKeyPair("DD06232AE9A50384A72D85CED6351DCB35C798231D4985615C77D6847F83FC65", true); var handler = new AcceptChannelMessageHandler(mocks.ChannelLoggingService.Object, mocks.FundingService.Object, mocks.CommTxService.Object); var localSig = "3045022100a5c01383d3ec646d97e40f44318d49def817fcd61a0ef18008a665b3e151785502203e648efddd5838981ef55ec954be69c4a652d021e6081a100d034de366815e9b".HexToByteArray(); OpenChannelMessage openChannelMessage = new OpenChannelMessage() { ChainHash = NetworkParameters.BitcoinTestnet.ChainHash, TemporaryChannelId = "43497fd7f826957108f4a30fd9cec3aeba79972084e90ead01ea3309000000".HexToByteArray(), FundingSatoshis = 420000, PushMSat = 1000, DustLimitSatoshis = 500, MaxHtlcValueInFlightMSat = 50000, ChannelReserveSatoshis = 5000, HtlcMinimumMSat = 1100, FeeratePerKw = 150, ToSelfDelay = 133, MaxAcceptedHtlcs = 156, FundingPubKey = new ECKeyPair("0245b02f6672c2342fe3ced57118fcf4a0309327e32c335ce494365eb0d15b7200", false), RevocationBasepoint = new ECKeyPair("02d91224d91760f477df21d24713b713c681b084e508f48dc77ca14db549ba8ceb", false), PaymentBasepoint = new ECKeyPair("022b2aa486f5a8aca1898824ac3b2a8a15c92de813362846b992f94d923b143f92", false), DelayedPaymentBasepoint = new ECKeyPair("0250d049da6b5832a9f2416df3b0db52da127426c2b70a35ca9c270a72f3f840b5", false), HtlcBasepoint = new ECKeyPair("029d100efe40aa3f58985fa12bd0f5c75711449ff4d30adca6f1968a2200bbbf1a", false), FirstPerCommitmentPoint = new ECKeyPair("022b2aa486f5a8aca1898824ac3b2a8a15c92de813362846b992f94d923b143f92", false), ChannelFlags = 1 }; AcceptChannelMessage acceptChannelMessage = new AcceptChannelMessage() { TemporaryChannelId = "43497fd7f826957108f4a30fd9cec3aeba79972084e90ead01ea3309000000".HexToByteArray(), DustLimitSatoshis = 500, MaxHtlcValueInFlightMSat = 50000, ChannelReserveSatoshis = 5000, HtlcMinimumMSat = 1100, ToSelfDelay = 133, MaxAcceptedHtlcs = 156, FundingPubKey = new ECKeyPair("0299de4bbf495e5bbeb2456c2beb3f40450a3fa41aaa50819ae201f8ad69226bfe", false), RevocationBasepoint = new ECKeyPair("022b2aa486f5a8aca1898824ac3b2a8a15c92de813362846b992f94d923b143f92", false), PaymentBasepoint = new ECKeyPair("02d91224d91760f477df21d24713b713c681b084e508f48dc77ca14db549ba8ceb", false), DelayedPaymentBasepoint = new ECKeyPair("0341665cedb568e09f0ab2ab4a28bc2749620deacefb3dce61aac8251c91709d3a", false), HtlcBasepoint = new ECKeyPair("0336439e36e2bc1f264c6d3bc6e12db6256389bef2056c32e6267d6e285c2b2122", false), FirstPerCommitmentPoint = new ECKeyPair("039360132ab07e7f56d6782a644233da9c4c24845609fcd302cbedd69f69848358", false) }; PendingChannel pendingChannel = new PendingChannel(mocks.Peer.Object, openChannelMessage, revocationKey, 0); FundingTransaction fundingTransactionMock = mocks.CreateFundingTxMock(openChannelMessage.FundingPubKey, acceptChannelMessage.FundingPubKey); mocks.FundingService.Setup(f => f.CreateFundingTransaction(openChannelMessage.FundingSatoshis, openChannelMessage.FeeratePerKw, openChannelMessage.FundingPubKey, acceptChannelMessage.FundingPubKey)) .Returns(fundingTransactionMock); mocks.CommTxService.Setup(f => f.CreateInitialCommitmentTransactions(openChannelMessage, acceptChannelMessage, It.IsAny <LocalChannel>(), revocationKey)) .Callback <OpenChannelMessage, AcceptChannelMessage, LocalChannel, ECKeyPair>((openMessage, acceptMessage, channel, rkey) => { channel.RemoteCommitmentTxParameters = new CommitmentTransactionParameters(); channel.RemoteCommitmentTxParameters.LocalSignature = new TransactionSignature(localSig, SigHash.All); }); FundingCreatedMessage fundingCreatedMessage = handler.Handle(acceptChannelMessage, pendingChannel); Assert.Equal("15fadebd5a68d2d9f216a2dc5531c4dbc977eac0c42ab97899e21d549dddbefa", fundingCreatedMessage.FundingTransactionId.ToHex()); Assert.Equal(new TransactionSignature(localSig, SigHash.All).ToRawSignature().ToHex(), fundingCreatedMessage.Signature.ToHex()); Assert.Equal(0, fundingCreatedMessage.FundingOutputIndex); Assert.Equal("43497fd7f826957108f4a30fd9cec3aeba79972084e90ead01ea3309000000", fundingCreatedMessage.TemporaryChannelId.ToHex()); }