MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / GetFileData

Method GetFileData

src/tests/system_test.cpp:145–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143 }
144
145 bool GetFileData(const string& strFilePath, string& strFileData) {
146 FILE* file = fopen(strFilePath.c_str(), "rb+");
147 if (!file) {
148 return false;
149 }
150
151 unsigned long lSize;
152 fseek(file, 0, SEEK_END);
153 lSize = ftell(file);
154 rewind(file);
155
156 // allocate memory to contain the whole file:
157 char *buffer = (char*) malloc(sizeof(char) * lSize);
158 if (buffer == NULL) {
159 return false;
160 }
161
162 if (fread(buffer, 1, lSize, file) != lSize) {
163 if (buffer)
164 free(buffer);
165 throw runtime_error("read script file error");
166 }
167
168 CVmScript vmScript;
169 vmScript.GetRom().insert(vmScript.GetRom().end(), buffer, buffer + lSize);
170 string desp("this is description");
171 vmScript.memo.assign(desp.begin(), desp.end());
172 CDataStream ds(SER_DISK, CLIENT_VERSION);
173 ds << vmScript;
174
175 vector<unsigned char> vscript;
176 vscript.assign(ds.begin(), ds.end());
177
178 if (file)
179 fclose(file);
180 if (buffer)
181 free(buffer);
182
183 strFileData = HexStr(vscript);
184 return true;
185 }
186
187 bool IsScriptAccCreatedEx(const uint256& txid,int nConfirmHeight) {
188 int index = 0;

Callers

nothing calls this directly

Calls 5

fopenFunction · 0.85
HexStrFunction · 0.85
insertMethod · 0.45
endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected