Skip to content

Commit

Permalink
Expand top-level constants in contract's code
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Oct 11, 2023
1 parent 6e64ed7 commit 74bf859
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -712,14 +712,31 @@ protected async Task<MichelineArray> 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);
var micheCode = code.First(x => x is MichelinePrim p && p.Prim == PrimType.code);
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;
Expand Down

0 comments on commit 74bf859

Please sign in to comment.