public async Task Init(Block block, RawOperation op, RawOriginationContent content) { var sender = await Cache.Accounts.GetAsync(content.Source); sender.Delegate ??= Cache.Accounts.GetDelegate(sender.DelegateId); var manager = ManagerTz.Test(content.Script.Code, content.Script.Storage) ? (User)await Cache.Accounts.GetAsync(ManagerTz.GetManager(content.Script.Storage)) : null; var delegat = Cache.Accounts.GetDelegateOrDefault(content.Delegate); var contract = content.Metadata.Result.Status == "applied" ? new Contract { Id = Cache.AppState.NextAccountId(), Address = content.Metadata.Result.OriginatedContracts[0], Balance = content.Balance, Counter = 0, Delegate = delegat, DelegationLevel = delegat != null ? (int?)block.Level : null, Creator = sender, Manager = manager, Staked = delegat?.Staked ?? false, Type = AccountType.Contract, Kind = manager != null ? ContractKind.DelegatorContract : ContractKind.SmartContract } : null; Origination = new OriginationOperation { Id = Cache.AppState.NextOperationId(), Block = block, Level = block.Level, Timestamp = block.Timestamp, OpHash = op.Hash, Balance = content.Balance, BakerFee = content.Fee, Counter = content.Counter, GasLimit = content.GasLimit, StorageLimit = content.StorageLimit, Sender = sender, Manager = manager, Delegate = delegat, Contract = contract, Status = content.Metadata.Result.Status switch { "applied" => OperationStatus.Applied, "backtracked" => OperationStatus.Backtracked, "failed" => OperationStatus.Failed, "skipped" => OperationStatus.Skipped, _ => throw new Exception($"Invalid status '{content.Metadata.Result.Status}'") },
protected override ContractKind GetContractKind(JsonElement content) { return(ManagerTz.Test(content.Required("script").Required("code"), content.Required("script").Required("storage")) ? ContractKind.DelegatorContract : ContractKind.SmartContract); }
protected override async Task <User> GetManager(JsonElement content) { return(ManagerTz.Test(content.Required("script").Required("code"), content.Required("script").Required("storage")) ? (User)await Cache.Accounts.GetAsync(ManagerTz.GetManager(content.Required("script").Required("storage"))) : null); }