pragma solidity ^0.4.20;
contract FacePlat {
string[] keys;
struct Person {
string outid;
string name;
string face;
}
mapping(string => Person) Persons;
function create(string outid, string name, string face) public returns(bool) {
Persons[outid].outid = outid;
Persons[outid].name = name;
Persons[outid].face = face;
keys.push(outid);
return false;
}
function del(string outid) public returns(bool) {
delete Persons[outid];
bool b = false;
int index = -1;
for (uint i = 0; i < keys.length; i++) {
if (bytes(outid).length == bytes(keys[i]).length) {
if(keccak256(outid) == keccak256(keys[i])) {
b = true;
}
}
}
if(!b) {
return false;
}
for (uint j = 0; j < keys.length-1; j++) {
keys[j] = keys[j+1];
}
delete keys[keys.length-1];
keys.length--;
return false;
}
function update(string outid, string name, string face) public returns(bool) {
Persons[outid].outid = outid;
Persons[outid].name = name;
Persons[outid].face = face;
return true;
}
function read(string outid) public returns(bool, string,string,string) {
bool b = false;
for (uint i = 0; i < keys.length; i++) {
if (bytes(outid).length == bytes(keys[i]).length) {
if(keccak256(outid) == keccak256(keys[i])) {
b = true;
}
}
}
if(!b) {
return (false, "", "", "");
}
return (true, Persons[outid].outid,Persons[outid].name, Persons[outid].face);
}
function total() public returns(uint256) {
return keys.length;
}
function findAllKeys() public returns(string) {
string memory s;
for (uint i = 0; i < keys.length; i++) {
s = strcat(s, keys[i]);
s = strcat(s, "|");
}
return s;
}
function strcat(string _a, string _b) internal returns (string){
bytes memory _ba = bytes(_a);
bytes memory _bb = bytes(_b);
string memory ret = new string(_ba.length + _bb.length);
bytes memory bret = bytes(ret);
uint k = 0;
for (uint i = 0; i < _ba.length; i++)
bret[k++] = _ba[i];
for (i = 0; i < _bb.length; i++)
bret[k++] = _bb[i];
return string(ret);
}
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
2021-04-08 Hyperledger fabric 证书详解
2021-04-08 org3-crypto.yaml 详解
2020-04-08 redhat7.4 docker run启动容器报错container_linux.go:449
2020-04-08 centos7 yum下载安装报错:软件包与预期下载的不符
2020-04-08 Centos7默认安装的docker版本说明