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

Commit 45d45c3

Browse files
committed
lib/build.js: rm special formatting for storage blocks
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.
1 parent 9a4bbdb commit 45d45c3

2 files changed

Lines changed: 0 additions & 66 deletions

File tree

lib/build.js

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const {
1717
} = require("./util.js")
1818
const {
1919
collisionCheck,
20-
getStorageDef
2120
} = require("./storage.js");
2221
const KLAB_OUT = process.env.KLAB_OUT || "out";
2322

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

33-
let storages_blocks = Object
34-
.keys(act.storage || {})
35-
.map(subjectName => {
36-
// TODO - export this one level higher - all storages
37-
let isCreate = act.creates[subjectName];
38-
let max_key_length = Object
39-
.keys(act.storage[subjectName])
40-
.map(key => key.length)
41-
.reduce((a, l) => Math.max(a, l), 0);
42-
let max_lhs_length = Object
43-
.keys(act.storage[subjectName])
44-
.map(key => act.storage[subjectName][key][0].length)
45-
.reduce((a, l) => Math.max(a, l), 0);
46-
let storage = Object
47-
.keys(act.storage[subjectName])
48-
.map(key => {
49-
let rewrites = act.storage[subjectName][key];
50-
const key_ = /^(\d|\#)/.test(key) ? key : `#${subjectName == "ACCT_ID" ? act.subject : subjectName}.${key}`
51-
const def = getStorageDef(key_);
52-
if(!def && false) {
53-
warn(`Storage key ${key_} in ${act.subject}.${act.name} not declared!`)
54-
}
55-
rewrites[0] = rewrites[0] + " ".repeat(max_lhs_length - rewrites[0].length)
56-
let storage_str = " "
57-
+ key
58-
+ " ".repeat(max_key_length - key.length)
59-
+ " |-> "
60-
+ (isCreate ? rewrites[0] : rewrites.join(" => "))
61-
let comment_str = def && def.doc(key_) && (" // " + def.doc(key_) + "\n") || ""
62-
return comment_str + storage_str;
63-
})
64-
.join("\n")
65-
66-
// Return the storage block header + body
67-
// - append the contract name to the header when referencing external contracts
68-
// - preserve the creates header when present
69-
let prefix = isCreate ? "creates storage" : "storage"
70-
let header = prefix + (subjectName !== "ACCT_ID" ? " " + subjectName : "");
71-
return header + "\n\n" + storage + "\n";
72-
})
73-
.join("\n\n")
74-
7532
const code_ = text
76-
.split(/\n/)
77-
.reduce(({isStorage, display}, line) => {
78-
const isStorageBlock = (/^storage$/).test(line);
79-
const isOtherStorageBlock = (/^(storage|creates storage)\s+\w/).test(line);
80-
const isBlock = (/^\w/).test(line);
81-
const isStorage_ = isStorageBlock || isOtherStorageBlock || (isStorage && !isBlock);
82-
83-
return {
84-
isStorage: isStorage_,
85-
display: display
86-
.concat(
87-
isStorage_ && !isStorageBlock
88-
? []
89-
: isStorageBlock && storages_blocks || line
90-
)
91-
};
92-
}, {
93-
isStorage: false,
94-
display: []
95-
})
96-
.display
97-
.join("\n")
9833
.replace(/\/\/ doc:/g, "//")
9934
.replace(/\/\/ act:/g, "//")
10035
.replace(/\/\/(.*)\n/gm, (_1, _2, l) => `<span class="comment">//${_2}</span>\n`)

lib/storage.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,4 @@ const collisionCheck = act => {
125125

126126
module.exports = {
127127
collisionCheck,
128-
getStorageDef
129128
}

0 commit comments

Comments
 (0)