From 74bf859add71767e9f41d5ecda513666df0be4af Mon Sep 17 00:00:00 2001 From: Maksim Strebkov <257byte@gmail.com> Date: Wed, 11 Oct 2023 15:45:23 +0300 Subject: [PATCH] Expand top-level constants in contract's code --- .../Commits/Operations/OriginationsCommit.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Tzkt.Sync/Protocols/Handlers/Proto1/Commits/Operations/OriginationsCommit.cs b/Tzkt.Sync/Protocols/Handlers/Proto1/Commits/Operations/OriginationsCommit.cs index fcb6cb5f8..055c03b88 100644 --- a/Tzkt.Sync/Protocols/Handlers/Proto1/Commits/Operations/OriginationsCommit.cs +++ b/Tzkt.Sync/Protocols/Handlers/Proto1/Commits/Operations/OriginationsCommit.cs @@ -712,6 +712,24 @@ protected async Task ProcessCode(OriginationOperation originatio protected async Task ProcessScript(OriginationOperation origination, MichelineArray code, IMicheline storageValue) { + #region expand top-level constants + var constants = await Constants.Find(Db, code); + if (constants.Count > 0) + { + var depth = 0; + while (code.Any(x => x is MichelinePrim prim && prim.Prim == PrimType.constant) && depth++ <= 10_000) + { + for (int i = 0; i < code.Count; i++) + { + if (code[i] is MichelinePrim prim && prim.Prim == PrimType.constant) + { + code[i] = Micheline.FromBytes(constants.First(x => x.Address == (prim.Args[0] as MichelineString).Value).Value); + } + } + } + } + #endregion + var contract = origination.Contract; var micheParameter = code.First(x => x is MichelinePrim p && p.Prim == PrimType.parameter); var micheStorage = code.First(x => x is MichelinePrim p && p.Prim == PrimType.storage); @@ -719,7 +737,6 @@ protected async Task ProcessScript(OriginationOperation origination, MichelineAr var micheViews = code.Where(x => x is MichelinePrim p && p.Prim == PrimType.view); #region process constants - var constants = await Constants.Find(Db, code); if (constants.Count > 0) { contract.Tags |= ContractTags.Constants;