public override void AddContract(WalletContract contract) { base.AddContract(contract); using (WalletDataContext ctx = new WalletDataContext(DbPath)) { Contract db_contract = ctx.Contracts.FirstOrDefault(p => p.ScriptHash.SequenceEqual(contract.ScriptHash.ToArray())); if (db_contract != null) { db_contract.PublicKeyHash = contract.PublicKeyHash.ToArray(); } else { Address db_address = ctx.Addresses.FirstOrDefault(p => p.ScriptHash.SequenceEqual(contract.ScriptHash.ToArray())); if (db_address == null) { ctx.Addresses.Add(new Address { ScriptHash = contract.ScriptHash.ToArray() }); } ctx.Contracts.Add(new Contract { RawData = contract.ToArray(), ScriptHash = contract.ScriptHash.ToArray(), PublicKeyHash = contract.PublicKeyHash.ToArray() }); } ctx.SaveChanges(); } }
public override WalletAccount CreateAccount(byte[] privateKey) { WalletAccount account = base.CreateAccount(privateKey); OnCreateAccount(account); AddContract(WalletContract.CreateSignatureContract(account.PublicKey)); return(account); }
public override void AddContract(WalletContract contract) { base.AddContract(contract); using (WalletDataContext ctx = new WalletDataContext(DbPath)) { Contract db_contract = ctx.Contracts.FirstOrDefault(p => p.ScriptHash.SequenceEqual(contract.ScriptHash.ToArray())); if (db_contract == null) { db_contract = ctx.Contracts.Add(new Contract { Type = contract.GetType().ToString(), RawData = contract.ToArray(), ScriptHash = contract.ScriptHash.ToArray(), PublicKeyHash = contract.PublicKeyHash.ToArray() }).Entity; } else { db_contract.PublicKeyHash = contract.PublicKeyHash.ToArray(); } ctx.SaveChanges(); } }