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

Commit

Permalink
lib/build.js: rm special formatting for storage blocks
Browse files Browse the repository at this point in the history
Removes all special formatting for storage blocks. This was interacting
badly with the multiline storage conditions that are commonly used in
k-uniswap.

Readable formatting for storage blocks is now the responsibility of the
spec author.
  • Loading branch information
d-xo committed Apr 10, 2020
1 parent 9a4bbdb commit 45d45c3
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 66 deletions.
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
}

0 comments on commit 45d45c3

Please sign in to comment.