MCPcopy Create free account
hub / github.com/ElementsProject/elements / RegisterLoad

Function RegisterLoad

src/bitcoin-tx.cpp:156–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154}
155
156static void RegisterLoad(const std::string& strInput)
157{
158 // separate NAME:FILENAME in string
159 size_t pos = strInput.find(':');
160 if ((pos == std::string::npos) ||
161 (pos == 0) ||
162 (pos == (strInput.size() - 1)))
163 throw std::runtime_error("Register load requires NAME:FILENAME");
164
165 std::string key = strInput.substr(0, pos);
166 std::string filename = strInput.substr(pos + 1, std::string::npos);
167
168 FILE *f = fsbridge::fopen(filename.c_str(), "r");
169 if (!f) {
170 std::string strErr = "Cannot open file " + filename;
171 throw std::runtime_error(strErr);
172 }
173
174 // load file chunks into one big buffer
175 std::string valStr;
176 while ((!feof(f)) && (!ferror(f))) {
177 char buf[4096];
178 int bread = fread(buf, 1, sizeof(buf), f);
179 if (bread <= 0)
180 break;
181
182 valStr.insert(valStr.size(), buf, bread);
183 }
184
185 int error = ferror(f);
186 fclose(f);
187
188 if (error) {
189 std::string strErr = "Error reading file " + filename;
190 throw std::runtime_error(strErr);
191 }
192
193 // evaluate as JSON buffer register
194 RegisterSetJson(key, valStr);
195}
196
197static CAmount ExtractAndValidateValue(const std::string& strValue)
198{

Callers 1

MutateTxFunction · 0.85

Calls 5

fopenFunction · 0.85
RegisterSetJsonFunction · 0.85
findMethod · 0.80
sizeMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected