SlideShare une entreprise Scribd logo
1  sur  35
Télécharger pour lire hors ligne
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
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

Contenu connexe

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

C++ Course - Lesson 3
C++ Course - Lesson 3C++ Course - Lesson 3
C++ Course - Lesson 3
Mohamed Ahmed
 
C# Advanced L02-Operator Overloading+Indexers+UD Conversion
C# Advanced L02-Operator Overloading+Indexers+UD ConversionC# Advanced L02-Operator Overloading+Indexers+UD Conversion
C# Advanced L02-Operator Overloading+Indexers+UD Conversion
Mohammad Shaker
 
Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008
Luis Enrique
 
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Victor Rentea
 

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

Benefits of Using MongoDB Over RDBMSs
Benefits of Using MongoDB Over RDBMSsBenefits of Using MongoDB Over RDBMSs
Benefits of Using MongoDB Over RDBMSs
 
Strctures,strings,pointers
Strctures,strings,pointersStrctures,strings,pointers
Strctures,strings,pointers
 
Building Services With gRPC, Docker and Go
Building Services With gRPC, Docker and GoBuilding Services With gRPC, Docker and Go
Building Services With gRPC, Docker and Go
 
C++ tutorials
C++ tutorialsC++ tutorials
C++ tutorials
 
Lab 13
Lab 13Lab 13
Lab 13
 
Knots - the Lazy Data Transfer Objects for Dealing with the Microservices Craze
Knots - the Lazy Data Transfer Objects for Dealing with the Microservices CrazeKnots - the Lazy Data Transfer Objects for Dealing with the Microservices Craze
Knots - the Lazy Data Transfer Objects for Dealing with the Microservices Craze
 
Chapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part IChapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part I
 
DDD - 2 - Domain Driven Design: Tactical design.pdf
DDD - 2 - Domain Driven Design: Tactical design.pdfDDD - 2 - Domain Driven Design: Tactical design.pdf
DDD - 2 - Domain Driven Design: Tactical design.pdf
 
C++ Course - Lesson 3
C++ Course - Lesson 3C++ Course - Lesson 3
C++ Course - Lesson 3
 
CHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxCHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptx
 
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
 
C# Advanced L02-Operator Overloading+Indexers+UD Conversion
C# Advanced L02-Operator Overloading+Indexers+UD ConversionC# Advanced L02-Operator Overloading+Indexers+UD Conversion
C# Advanced L02-Operator Overloading+Indexers+UD Conversion
 
Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008
 
Writing MySQL UDFs
Writing MySQL UDFsWriting MySQL UDFs
Writing MySQL UDFs
 
Angular JS2 Training Session #1
Angular JS2 Training Session #1Angular JS2 Training Session #1
Angular JS2 Training Session #1
 
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
 
RMLL 2013 - Synchronize OpenLDAP and Active Directory with LSC
RMLL 2013 - Synchronize OpenLDAP and Active Directory with LSCRMLL 2013 - Synchronize OpenLDAP and Active Directory with LSC
RMLL 2013 - Synchronize OpenLDAP and Active Directory with LSC
 
Capstone ms2
Capstone ms2Capstone ms2
Capstone ms2
 
Get together on getting more out of typescript & angular 2
Get together on getting more out of typescript & angular 2Get together on getting more out of typescript & angular 2
Get together on getting more out of typescript & angular 2
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003
 

Plus de Mark Smalley

Why I Believe MongoDB is The Dog's Bollocks
Why I Believe MongoDB is The Dog's BollocksWhy I Believe MongoDB is The Dog's Bollocks
Why I Believe MongoDB is The Dog's Bollocks
Mark Smalley
 

Plus de Mark Smalley (19)

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

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

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
  • 6.
  • 7.
  • 8.
  • 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