SlideShare a Scribd company logo
BLOCKCHAIN DEVELOPERS MALAYSIA
http://neuroware.io
Meetup #4 - Back to Tech - March, 2018
sponsored by
BLOCKCHAIN DEVELOPER PRESENTATIONS & LIVE DEMOS
MARK SMALLEY ( Neuroware.io ) - CRUDy Ethereum Contracts
TM LEE ( CoinGecko.com ) - Crypto Wallet Walkthroughs
ADAM MASHRIQUE ( LuxTag.io ) - Lightning Networks via Vue.js
CRUDy Ethereum Contracts
PART 1 - CREATE, READ, UPDATE & DELETE DATA
INTRODUCING THE BIG BLOCK BITCOIN MINIMALIST
Mark Smalley - CEO ( Neuroware.io )
Living in Malaysia for the past 20 Years
Building FinTech Applications for 15 Years
Spent 10 Years Helping Tech Communities
Building Blockchain Apps for 5 Years
INTRODUCING R1 DOT MY SDN BHD
GLOBAL
FUNDING
Only Malaysian company to graduate
from 500 Startups Accelerator in Silicon
Valley, with funding from Coinsilium too
FINTECH
FOCUS
With DBS, Maybank and Securities
Commission of Malaysia as clients, we
have a broad understanding of fintech
FULL-STACK
SERVICES
We provide corporate blockchain
training and workshops along with
consulting on solutions utilizing Cortex
NEUROWARE
enterprise infrastructure
BCE.ASIA
consortium
BLOCKSTRAP
framework
ENOUGH ABOUT ME
LET’S RECAP LAST MONTH’S TOPIC
TOKENIZING ASSETS WITH BLOCKCHAINS
Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet Walkthrough and Lightning via VueJS
Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet Walkthrough and Lightning via VueJS
Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet Walkthrough and Lightning via VueJS
ENOUGH ABOUT THE BLOCKCHAIN EMBASSY OF ASIA (www.BCE.asia)
WHY ARE WE TALKING ABOUT CRUDY CONTRACTS …?
IMMUTABLE CODE IS VERY DIFFERENT TO IMMUTABLE DATA
MOVING BEYOND TOKEN GENERATION
CREATE READ UPDATE DESTROY
ETHEREUM’S BIGGEST SURPRISES
● An object oriented language without objects
● A static typing language with only one type
● Indexes via mapped hash tables cannot be removed
● Indexes cannot be natively counted
● Moving beyond 32 byte dynamic chunks is complicated
● Output functionality is even more restrictive than inputs
ONE TYPE TO RULE THEM ALL
Inline data types available within contracts includes:
● Booleans
● Integers
● Addresses
● Strings
● Bytes
Data types stored on the blockchain:
● Byte arrays
DEFINING VARIABLE TYPES AND THEIR VISIBILITY
contract CRM
{
bool internal deactivated = 0;
uint public contact_count = 0;
address private contract_owner;
string external owner_name = “Mark”;
function CRM(string name)
{
contract_owner = msg.sender;
owner_name = name;
}
}
Global variables automatically available
anywhere within the contract include:
● block (current height, gas, difficulty, etc)
● msg (data, gas, sender, value, etc)
● now (alias for block.timestamp)
● tx (gas price & origin)
function is auto initiated if its
the same as contract name
ONE DIMENSIONAL ARRAYS
● All four data types (other than strings) can be set as arrays
● Arrays can only contain the same data type
● Constructing arrays within functions requires length definitions
● Don’t forget that strings are also arrays (chunks are relative)
● Arrays used for input & output parameters cannot be strings
USING ARRAYS
contract CRM
{
uint[] private owner_ip_address;
address[] public owners;
function SwitchOwner(string ip_address, address new_owner)
{
if(msg.sender == contract_owner)
{
contract_owner = new_owner;
owners.push(contract_owner);
owner_ip_address = string_to_array(ip_address, “.”);
}
}
}
BUILDING NEW ARRAYS
uint[] private owner_ip4_address;
address[] public owners;
uint[] public owner_switch_blocks;
function SwitchOwner(string ip_address, address new_owner)
returns(uint[] previous_owner)
{
uint[] memory previous = new uint[](6);
if(msg.sender == contract_owner)
{
contract_owner = new_owner;
owners.push(contract_owner);
owner_switch_blocks.push(block.number);
owner_ip_address = string_to_array (ip_address, “.”);
previous[0 to 3] = owner_ip_address[0 to 3];
previous[4] = owner_switch_blocks[owner_switch_blocks.length - 1];
previous[5] = owner_switch_blocks.length;
}
return previous; // Everything but the name :-(
}
STRUCTS TO THE RESCUE !!! ???
contract CRM
{
struct owner
{
address id;
string name;
uint[] ip;
}
owner[] public owners; // manual auto inc id ???
function CRM(string owner_name, uint[] ip_address)
{
owner new_owner;
new_owners.id = msg.sender;
new_owners.name = owner_name;
new_owners.ip = ip_address;
owners.push(new_owner);
}
}
INDEXING VIA HASH TABLES - ALREADY REMOVES 4 LINES
contract CRM
{
struct owner
{
string name;
uint[] ip;
}
mapping(address => owner) owners;
function CRM(string owner_name, uint[] ip_address)
{
// can then create, read & update with key ...
owners[msg.sender].name = owner_name;
owners[msg.sender].ip = ip_address;
}
}
HOWEVER
● Structs cannot be returned
● Struct parameters cannot be counted natively
● Mappings cannot be counted
-- which requires index counts to be managed separately
● Mappings cannot be removed
● Mappings cannot be collectively returned
-- returned results must also be singular types of arrays
IN ALL HONESTY - IT’S BYTES THAT SAVE THE DAY !!!
struct owner
{
string name;
uint[] ip;
}
mapping(address => owner) owners;
uint owner_count = 0;
function CRM(string owner_name, uint[] ip_address)
returns(bytes32[] owner)
{
bytes32[] memory new_owner = new bytes32[](2);
new_owner[0] = string_to_bytes (owner_name);
new_owner[1] = combine(ip_address[0 to 4])
owners[msg.sender].name = owner_name;
owners[msg.sender].ip = ip_address;
owner_count++; // manual owner count management
return new_owner
}
THE ONLY WAY TO DELETE - STEP 1 - BE PREPARED ???
struct owner
{
bool is_active;
string name;
uint[] ip;
}
mapping(address => owner) owners;
uint owner_count = 0;
function CRM(string owner_name, uint[] ip_address)
{
bytes32[] memory new_owner = new bytes32[](2);
owners[msg.sender].is_active = 1; // activate
owners[msg.sender].name = owner_name;
owners[msg.sender].ip = ip_address;
owner_count++; // manual owner count management
}
THE ONLY WAY TO DELETE - STEP 2 - COST EFFECTIVE UPDATING
struct owner
{
bool is_active;
string name;
uint[] ip;
}
mapping(address => owner) owners;
uint owner_count = 0;
function destroy(address owner_id)
{
owners[owner_id].is_active = 0; // this costs ether
owner_count--; // manual owner count management
}
WRITING DATA COSTS MONEY
CRUDy RECAP - CREATE NEW RECORD
contract CRM
{
struct user
{
string name;
string email;
bool is_active;
}
mapping(address => user) users;
function create(
address user_address,
string user_name,
string user_email
) onlyOwner public {
users[user_address].is_active = 1;
users[user_address].name = user_name;
users[user_address].email = user_email;
}
}
CRUDy RECAP - READ RECORD
contract CRM
{
struct user
{
string name;
string email;
bool is_active;
}
mapping(address => user) users;
function read(address user_address) public
returns(string user_name, string user_email)
{
return(
users[user_address].name,
users[user_address].email
)
}
}
CRUDy RECAP - UPDATE RECORDED DATA BY INDEX
contract CRM
{
struct user
{
string name;
string email;
bool is_active;
}
mapping(address => user) users;
function update(
address user_address,
string user_name,
string user_email
) onlyOwner public {
require(users[user_address].is_active == 1);
users[user_address].name = user_name;
users[user_address].email = user_email;
}
}
CRUDy RECAP - UPDATE INDEX
contract CRM
{
struct user
{
string name;
string email;
bool is_active;
}
mapping(address => user) users;
function update_index(
address old_address,
string new_address
) onlyOwner public {
require(users[old_address].is_active == 1);
users[new_address].name = users[old_address].name;
users[new_address].email = users[old_address].email;
users[new_address].is_active = 1;
users[old_address].is_active = 0;
}
}
CRUDy RECAP - DESTROY RECORDS
contract CRM
{
struct user
{
string name;
string email;
bool is_active;
}
mapping(address => user) users;
function destroy(address user_address) onlyOwner public
{
require(users[user_address].is_active == 1);
users[user_address].is_active = 0;
}
}
CRUDy RECAP - COMPLICATED BY COUNTS
contract CRM
{
struct user
{
string name;
string email;
bool is_active;
}
mapping(address => user) users;
uint public user_count;
function destroy(address user_address) onlyOwner public
{
require(users[user_address].is_active == 1);
users[user_address].is_active = 0;
user_count--;
}
}
CRUDy RECAP - EVEN MORE SO WITH JOINS
struct user
{
string name;
string email;
bool is_active;
uint index_key;
}
mapping(address => user) users;
address[] public user_indexes;
function destroy(address user_address) onlyOwner public
{
require(users[user_address].is_active == 1);
users[user_address].is_active = 0;
users[user_indexes[user_indexes.length - 1]].index_key =
users[user_address].index_key
user_indexes[users[user_address].index_key] =
user_indexes[user_indexes.length - 1];
user_indexes.length = user_index.length - 1;
}
CAVEATS - WORKING WITH STRINGS
● Since strings cannot be returned from external contracts every
contract dealing with strings needs it own conversion functions
● Converting strings to 32 byte arrays allow anything to be
returned - so long as each value is within 32 bytes, which
also requires the decoding to be done by the client
● Which brings us to what I thought we would cover today ...
WHAT ABOUT CRUD BEYOND PREDEFINED STRUCTURE ???
CREATE READ UPDATE DESTROY
TO BE CONTINUED IN PART 2
CREATING A DATABASE WITHIN A CONTRACT
email the team anytime - founders@neuroware.io

More Related Content

PPTX
Cs1123 12 structures
PDF
Java beginners meetup: Introduction to class and application design
PDF
React in 45 Minutes (Jfokus)
PPT
Java căn bản - Chapter4
PDF
MongoDB Days Silicon Valley: Building an Artificial Intelligence Startup with...
PPTX
Building an An AI Startup with MongoDB at x.ai
PPTX
Constructor&method
PPTX
Transitioning from SQL to MongoDB
Cs1123 12 structures
Java beginners meetup: Introduction to class and application design
React in 45 Minutes (Jfokus)
Java căn bản - Chapter4
MongoDB Days Silicon Valley: Building an Artificial Intelligence Startup with...
Building an An AI Startup with MongoDB at x.ai
Constructor&method
Transitioning from SQL to MongoDB

Similar to Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet Walkthrough and Lightning via VueJS (20)

PPTX
Benefits of Using MongoDB Over RDBMSs
PDF
Object Oriented Programming (OOP) using C++ - Lecture 1
PPTX
PDF
Building Services With gRPC, Docker and Go
PDF
Visual Programming Lacture Nine 9 Structure.pdf
PDF
Solidity programming language and its different concepts with an example
PPT
C++ tutorials
PPTX
Lab 13
ODP
Knots - the Lazy Data Transfer Objects for Dealing with the Microservices Craze
PPT
Chapter 4 - Defining Your Own Classes - Part I
PDF
DDD - 2 - Domain Driven Design: Tactical design.pdf
PDF
C++ Course - Lesson 3
PPTX
CHAPTER -4-class and structure.pptx
PPTX
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
PDF
C# Advanced L02-Operator Overloading+Indexers+UD Conversion
PPT
Visual studio 2008
PPTX
How to add Many2Many fields in odoo website form.pptx
ODP
Writing MySQL UDFs
PDF
Angular JS2 Training Session #1
PDF
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Benefits of Using MongoDB Over RDBMSs
Object Oriented Programming (OOP) using C++ - Lecture 1
Building Services With gRPC, Docker and Go
Visual Programming Lacture Nine 9 Structure.pdf
Solidity programming language and its different concepts with an example
C++ tutorials
Lab 13
Knots - the Lazy Data Transfer Objects for Dealing with the Microservices Craze
Chapter 4 - Defining Your Own Classes - Part I
DDD - 2 - Domain Driven Design: Tactical design.pdf
C++ Course - Lesson 3
CHAPTER -4-class and structure.pptx
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
C# Advanced L02-Operator Overloading+Indexers+UD Conversion
Visual studio 2008
How to add Many2Many fields in odoo website form.pptx
Writing MySQL UDFs
Angular JS2 Training Session #1
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Ad

More from Mark Smalley (19)

PDF
An Introduction to Upgradable Smart Contracts
PDF
BDM Meetup 2 - Blockchain Basics - Generating Keys for BloqPress
PDF
BDM Meetup #1 - Blockchains for Developers - Part 01
PDF
Neuroware.io at FINNOVASIA KL - 2016
PDF
Banking on The Future of Blockchains
PDF
LVLUPKL - My Life on The Blockchain
PDF
Blockstrap at FOSS Asia - 2015 - Building Browser-Based Blockchain Applications
PDF
Bitcoin is Still Technology - Presented at Bitcoin World Conference KL - 2014
PPTX
Logging-In with Bitcoin - Paywalls without Emails
PPTX
Programmable Money - Visual Guide to Bitcoin as a Technology
PDF
Introducing Bitcoin :: The (Mostly) Visual-Guide to Cryptographic Currencies
PDF
1st NoSQL Asia Event in Malaysia
PDF
MongoDB Day KL - 2013 :: Keynote - The State of MongoDB in Malaysia
PDF
JSON, The Argonauts and Mark
PPTX
JSON and The Argonauts
PDF
KL MUG 9
KEY
Serving Images with GridFS
ODP
Why I Believe MongoDB is The Dog's Bollocks
PPT
Introducing MongoPress
An Introduction to Upgradable Smart Contracts
BDM Meetup 2 - Blockchain Basics - Generating Keys for BloqPress
BDM Meetup #1 - Blockchains for Developers - Part 01
Neuroware.io at FINNOVASIA KL - 2016
Banking on The Future of Blockchains
LVLUPKL - My Life on The Blockchain
Blockstrap at FOSS Asia - 2015 - Building Browser-Based Blockchain Applications
Bitcoin is Still Technology - Presented at Bitcoin World Conference KL - 2014
Logging-In with Bitcoin - Paywalls without Emails
Programmable Money - Visual Guide to Bitcoin as a Technology
Introducing Bitcoin :: The (Mostly) Visual-Guide to Cryptographic Currencies
1st NoSQL Asia Event in Malaysia
MongoDB Day KL - 2013 :: Keynote - The State of MongoDB in Malaysia
JSON, The Argonauts and Mark
JSON and The Argonauts
KL MUG 9
Serving Images with GridFS
Why I Believe MongoDB is The Dog's Bollocks
Introducing MongoPress
Ad

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Approach and Philosophy of On baking technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Big Data Technologies - Introduction.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Electronic commerce courselecture one. Pdf
PPT
Teaching material agriculture food technology
PDF
Encapsulation theory and applications.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Unlocking AI with Model Context Protocol (MCP)
Spectral efficient network and resource selection model in 5G networks
Chapter 3 Spatial Domain Image Processing.pdf
cuic standard and advanced reporting.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
20250228 LYD VKU AI Blended-Learning.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
The Rise and Fall of 3GPP – Time for a Sabbatical?
sap open course for s4hana steps from ECC to s4
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Approach and Philosophy of On baking technology
Network Security Unit 5.pdf for BCA BBA.
Big Data Technologies - Introduction.pptx
Empathic Computing: Creating Shared Understanding
Electronic commerce courselecture one. Pdf
Teaching material agriculture food technology
Encapsulation theory and applications.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Unlocking AI with Model Context Protocol (MCP)

Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet Walkthrough and Lightning via VueJS

  • 1. BLOCKCHAIN DEVELOPERS MALAYSIA http://neuroware.io Meetup #4 - Back to Tech - March, 2018 sponsored by BLOCKCHAIN DEVELOPER PRESENTATIONS & LIVE DEMOS MARK SMALLEY ( Neuroware.io ) - CRUDy Ethereum Contracts TM LEE ( CoinGecko.com ) - Crypto Wallet Walkthroughs ADAM MASHRIQUE ( LuxTag.io ) - Lightning Networks via Vue.js
  • 2. CRUDy Ethereum Contracts PART 1 - CREATE, READ, UPDATE & DELETE DATA
  • 3. INTRODUCING THE BIG BLOCK BITCOIN MINIMALIST Mark Smalley - CEO ( Neuroware.io ) Living in Malaysia for the past 20 Years Building FinTech Applications for 15 Years Spent 10 Years Helping Tech Communities Building Blockchain Apps for 5 Years
  • 4. INTRODUCING R1 DOT MY SDN BHD GLOBAL FUNDING Only Malaysian company to graduate from 500 Startups Accelerator in Silicon Valley, with funding from Coinsilium too FINTECH FOCUS With DBS, Maybank and Securities Commission of Malaysia as clients, we have a broad understanding of fintech FULL-STACK SERVICES We provide corporate blockchain training and workshops along with consulting on solutions utilizing Cortex NEUROWARE enterprise infrastructure BCE.ASIA consortium BLOCKSTRAP framework
  • 5. ENOUGH ABOUT ME LET’S RECAP LAST MONTH’S TOPIC TOKENIZING ASSETS WITH BLOCKCHAINS
  • 9. ENOUGH ABOUT THE BLOCKCHAIN EMBASSY OF ASIA (www.BCE.asia) WHY ARE WE TALKING ABOUT CRUDY CONTRACTS …?
  • 10. IMMUTABLE CODE IS VERY DIFFERENT TO IMMUTABLE DATA
  • 11. MOVING BEYOND TOKEN GENERATION CREATE READ UPDATE DESTROY
  • 12. ETHEREUM’S BIGGEST SURPRISES ● An object oriented language without objects ● A static typing language with only one type ● Indexes via mapped hash tables cannot be removed ● Indexes cannot be natively counted ● Moving beyond 32 byte dynamic chunks is complicated ● Output functionality is even more restrictive than inputs
  • 13. ONE TYPE TO RULE THEM ALL Inline data types available within contracts includes: ● Booleans ● Integers ● Addresses ● Strings ● Bytes Data types stored on the blockchain: ● Byte arrays
  • 14. DEFINING VARIABLE TYPES AND THEIR VISIBILITY contract CRM { bool internal deactivated = 0; uint public contact_count = 0; address private contract_owner; string external owner_name = “Mark”; function CRM(string name) { contract_owner = msg.sender; owner_name = name; } } Global variables automatically available anywhere within the contract include: ● block (current height, gas, difficulty, etc) ● msg (data, gas, sender, value, etc) ● now (alias for block.timestamp) ● tx (gas price & origin) function is auto initiated if its the same as contract name
  • 15. ONE DIMENSIONAL ARRAYS ● All four data types (other than strings) can be set as arrays ● Arrays can only contain the same data type ● Constructing arrays within functions requires length definitions ● Don’t forget that strings are also arrays (chunks are relative) ● Arrays used for input & output parameters cannot be strings
  • 16. USING ARRAYS contract CRM { uint[] private owner_ip_address; address[] public owners; function SwitchOwner(string ip_address, address new_owner) { if(msg.sender == contract_owner) { contract_owner = new_owner; owners.push(contract_owner); owner_ip_address = string_to_array(ip_address, “.”); } } }
  • 17. BUILDING NEW ARRAYS uint[] private owner_ip4_address; address[] public owners; uint[] public owner_switch_blocks; function SwitchOwner(string ip_address, address new_owner) returns(uint[] previous_owner) { uint[] memory previous = new uint[](6); if(msg.sender == contract_owner) { contract_owner = new_owner; owners.push(contract_owner); owner_switch_blocks.push(block.number); owner_ip_address = string_to_array (ip_address, “.”); previous[0 to 3] = owner_ip_address[0 to 3]; previous[4] = owner_switch_blocks[owner_switch_blocks.length - 1]; previous[5] = owner_switch_blocks.length; } return previous; // Everything but the name :-( }
  • 18. STRUCTS TO THE RESCUE !!! ??? contract CRM { struct owner { address id; string name; uint[] ip; } owner[] public owners; // manual auto inc id ??? function CRM(string owner_name, uint[] ip_address) { owner new_owner; new_owners.id = msg.sender; new_owners.name = owner_name; new_owners.ip = ip_address; owners.push(new_owner); } }
  • 19. INDEXING VIA HASH TABLES - ALREADY REMOVES 4 LINES contract CRM { struct owner { string name; uint[] ip; } mapping(address => owner) owners; function CRM(string owner_name, uint[] ip_address) { // can then create, read & update with key ... owners[msg.sender].name = owner_name; owners[msg.sender].ip = ip_address; } }
  • 20. HOWEVER ● Structs cannot be returned ● Struct parameters cannot be counted natively ● Mappings cannot be counted -- which requires index counts to be managed separately ● Mappings cannot be removed ● Mappings cannot be collectively returned -- returned results must also be singular types of arrays
  • 21. IN ALL HONESTY - IT’S BYTES THAT SAVE THE DAY !!! struct owner { string name; uint[] ip; } mapping(address => owner) owners; uint owner_count = 0; function CRM(string owner_name, uint[] ip_address) returns(bytes32[] owner) { bytes32[] memory new_owner = new bytes32[](2); new_owner[0] = string_to_bytes (owner_name); new_owner[1] = combine(ip_address[0 to 4]) owners[msg.sender].name = owner_name; owners[msg.sender].ip = ip_address; owner_count++; // manual owner count management return new_owner }
  • 22. THE ONLY WAY TO DELETE - STEP 1 - BE PREPARED ??? struct owner { bool is_active; string name; uint[] ip; } mapping(address => owner) owners; uint owner_count = 0; function CRM(string owner_name, uint[] ip_address) { bytes32[] memory new_owner = new bytes32[](2); owners[msg.sender].is_active = 1; // activate owners[msg.sender].name = owner_name; owners[msg.sender].ip = ip_address; owner_count++; // manual owner count management }
  • 23. THE ONLY WAY TO DELETE - STEP 2 - COST EFFECTIVE UPDATING struct owner { bool is_active; string name; uint[] ip; } mapping(address => owner) owners; uint owner_count = 0; function destroy(address owner_id) { owners[owner_id].is_active = 0; // this costs ether owner_count--; // manual owner count management }
  • 25. CRUDy RECAP - CREATE NEW RECORD contract CRM { struct user { string name; string email; bool is_active; } mapping(address => user) users; function create( address user_address, string user_name, string user_email ) onlyOwner public { users[user_address].is_active = 1; users[user_address].name = user_name; users[user_address].email = user_email; } }
  • 26. CRUDy RECAP - READ RECORD contract CRM { struct user { string name; string email; bool is_active; } mapping(address => user) users; function read(address user_address) public returns(string user_name, string user_email) { return( users[user_address].name, users[user_address].email ) } }
  • 27. CRUDy RECAP - UPDATE RECORDED DATA BY INDEX contract CRM { struct user { string name; string email; bool is_active; } mapping(address => user) users; function update( address user_address, string user_name, string user_email ) onlyOwner public { require(users[user_address].is_active == 1); users[user_address].name = user_name; users[user_address].email = user_email; } }
  • 28. CRUDy RECAP - UPDATE INDEX contract CRM { struct user { string name; string email; bool is_active; } mapping(address => user) users; function update_index( address old_address, string new_address ) onlyOwner public { require(users[old_address].is_active == 1); users[new_address].name = users[old_address].name; users[new_address].email = users[old_address].email; users[new_address].is_active = 1; users[old_address].is_active = 0; } }
  • 29. CRUDy RECAP - DESTROY RECORDS contract CRM { struct user { string name; string email; bool is_active; } mapping(address => user) users; function destroy(address user_address) onlyOwner public { require(users[user_address].is_active == 1); users[user_address].is_active = 0; } }
  • 30. CRUDy RECAP - COMPLICATED BY COUNTS contract CRM { struct user { string name; string email; bool is_active; } mapping(address => user) users; uint public user_count; function destroy(address user_address) onlyOwner public { require(users[user_address].is_active == 1); users[user_address].is_active = 0; user_count--; } }
  • 31. CRUDy RECAP - EVEN MORE SO WITH JOINS struct user { string name; string email; bool is_active; uint index_key; } mapping(address => user) users; address[] public user_indexes; function destroy(address user_address) onlyOwner public { require(users[user_address].is_active == 1); users[user_address].is_active = 0; users[user_indexes[user_indexes.length - 1]].index_key = users[user_address].index_key user_indexes[users[user_address].index_key] = user_indexes[user_indexes.length - 1]; user_indexes.length = user_index.length - 1; }
  • 32. CAVEATS - WORKING WITH STRINGS ● Since strings cannot be returned from external contracts every contract dealing with strings needs it own conversion functions ● Converting strings to 32 byte arrays allow anything to be returned - so long as each value is within 32 bytes, which also requires the decoding to be done by the client ● Which brings us to what I thought we would cover today ...
  • 33. WHAT ABOUT CRUD BEYOND PREDEFINED STRUCTURE ??? CREATE READ UPDATE DESTROY
  • 34. TO BE CONTINUED IN PART 2 CREATING A DATABASE WITHIN A CONTRACT
  • 35. email the team anytime - founders@neuroware.io