Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

lib/build.js: rm special formatting for storage blocks #397

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 0 additions & 65 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const {
} = require("./util.js")
const {
collisionCheck,
getStorageDef
} = require("./storage.js");
const KLAB_OUT = process.env.KLAB_OUT || "out";

Expand All @@ -30,71 +29,7 @@ const BIG_GAS = 3000000;
const h = n => s => `<${Array.isArray(n) ? n.join(' ') : n}>${Array.isArray(s) && s.join('') || s}</${Array.isArray(n) ? n[0] : n}>`
const newCleanup = (act, text) => {

let storages_blocks = Object
.keys(act.storage || {})
.map(subjectName => {
// TODO - export this one level higher - all storages
let isCreate = act.creates[subjectName];
let max_key_length = Object
.keys(act.storage[subjectName])
.map(key => key.length)
.reduce((a, l) => Math.max(a, l), 0);
let max_lhs_length = Object
.keys(act.storage[subjectName])
.map(key => act.storage[subjectName][key][0].length)
.reduce((a, l) => Math.max(a, l), 0);
let storage = Object
.keys(act.storage[subjectName])
.map(key => {
let rewrites = act.storage[subjectName][key];
const key_ = /^(\d|\#)/.test(key) ? key : `#${subjectName == "ACCT_ID" ? act.subject : subjectName}.${key}`
const def = getStorageDef(key_);
if(!def && false) {
warn(`Storage key ${key_} in ${act.subject}.${act.name} not declared!`)
}
rewrites[0] = rewrites[0] + " ".repeat(max_lhs_length - rewrites[0].length)
let storage_str = " "
+ key
+ " ".repeat(max_key_length - key.length)
+ " |-> "
+ (isCreate ? rewrites[0] : rewrites.join(" => "))
let comment_str = def && def.doc(key_) && (" // " + def.doc(key_) + "\n") || ""
return comment_str + storage_str;
})
.join("\n")

// Return the storage block header + body
// - append the contract name to the header when referencing external contracts
// - preserve the creates header when present
let prefix = isCreate ? "creates storage" : "storage"
let header = prefix + (subjectName !== "ACCT_ID" ? " " + subjectName : "");
return header + "\n\n" + storage + "\n";
})
.join("\n\n")

const code_ = text
.split(/\n/)
.reduce(({isStorage, display}, line) => {
const isStorageBlock = (/^storage$/).test(line);
const isOtherStorageBlock = (/^(storage|creates storage)\s+\w/).test(line);
const isBlock = (/^\w/).test(line);
const isStorage_ = isStorageBlock || isOtherStorageBlock || (isStorage && !isBlock);

return {
isStorage: isStorage_,
display: display
.concat(
isStorage_ && !isStorageBlock
? []
: isStorageBlock && storages_blocks || line
)
};
}, {
isStorage: false,
display: []
})
.display
.join("\n")
.replace(/\/\/ doc:/g, "//")
.replace(/\/\/ act:/g, "//")
.replace(/\/\/(.*)\n/gm, (_1, _2, l) => `<span class="comment">//${_2}</span>\n`)
Expand Down
1 change: 0 additions & 1 deletion lib/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,4 @@ const collisionCheck = act => {

module.exports = {
collisionCheck,
getStorageDef
}