SlideShare a Scribd company logo
Code Run of the Cosmos SDK
KVStore
KVStore
type	KVStore	interface	{		
				Store	
				Get(key	[]byte)	[]byte		
				Has(key	[]byte)	bool		
				Set(key,	value	[]byte)		
				Delete(key	[]byte)		
				Iterator(start,	end	[]byte)	Iterator		
				ReverseIterator(start,	end	[]byte)	Iterator		
}	
cosmos-sdk/types/store.go
Lines 91 to 121 in 3fc7200
Multiple KVStores
app.MountStoresIAVL(app.keyMain,	
app.keyAccount,	app.keyIBC,	
app.keyStake,	app.keySlashing)	
cosmos-sdk/examples/basecoin/app/app.go
Line 90 in 3fc7200
iavlStore
func	(st	*iavlStore)	Query(req	
abci.RequestQuery)	(res	
abci.ResponseQuery)	{	
cosmos-sdk/store/iavlstore.go
Line 135 in 3fc7200
go-amino
BaseAccount
	type	BaseAccount	struct	{		
				Address		sdk.Address			`json:"address"`		
				Coins				sdk.Coins					`json:"coins"`		
				PubKey			crypto.PubKey	`json:"public_key"`		
				Sequence	int64									`json:"sequence"`		
}	
cosmos-sdk/x/auth/account.go
lines of code in what commit
Register crypto
func	MakeCodec()	*wire.Codec	{	
				var	cdc	=	wire.NewCodec()	
				wire.RegisterCrypto(cdc)	//	Register	crypto.																												
				sdk.RegisterWire(cdc)				//	Register	Msgs	
				bank.RegisterWire(cdc)	
				stake.RegisterWire(cdc)	
				slashing.RegisterWire(cdc)	
				ibc.RegisterWire(cdc)	
				cdc.RegisterInterface((*auth.Account)(nil),	nil)	
				cdc.RegisterConcrete(&types.AppAccount{},	"basecoin/Account",	nil)	
				return	cdc	
}
cosmos-sdk/examples/basecoin/app/app.go
Line 101 in d309abb
More on go-amino
github.com/tendermint/go-amino
Keys,Keepers,and
Mappers
Hold a key — not a reference
type	AccountMapper	struct	{		
				//	The	(unexposed)	key	used	to	access	the	
				//	store	from	the	Context.	
				key	sdk.StoreKey		
				//	The	prototypical	Account	concrete	type.		
				proto	Account		
				//	wire	codec	for	binary	encoding	of	accounts.		
				cdc	*wire.Codec		
}	
cosmos-sdk/x/auth/mapper.go
Lines 14 to 24 in fc0e401
Define the accountMapper
app.accountMapper	=	
auth.NewAccountMapper(		
				cdc,		
				app.keyAccount,						//	target	store		
				&types.AppAccount{},	//	prototype		
)	
cosmos-sdk/examples/basecoin/app/app.go
Lines 65 to 70 in d309abb
Enable access with associated key
func	(am	AccountMapper)	GetAccount(ctx	sdk.Context,	
addr	sdk.Address)	Account	{		
				store	:=	ctx.KVStore(am.key)		
				bz	:=	store.Get(addr)		
				if	bz	==	nil	{	return	nil	}		
				acc	:=	am.decodeAccount(bz)		
				return	acc		
}	
cosmos-sdk/x/auth/mapper.go
Lines 44 to 53 in fc0e401
Tx,Msg,Handler,and
AnteHandler
StdTx
//	A	standard	way	to	wrap	a	Msg	
//		with	a	Fee	and	Signatures.		
	type	StdTx	struct	{		
				Msg								sdk.Msg								`json:"msg"`		
				Fee								StdFee									`json:"fee"`		
				Signatures	[]StdSignature	`json:"signatures"`		
}	
cosmos-sdk/x/auth/stdtx.go
Lines 12 to 18 in fc0e401
Register Msgs
func	MakeCodec()	*wire.Codec	{	
				var	cdc	=	wire.NewCodec()	
				wire.RegisterCrypto(cdc)	//	Register	crypto.																												
				sdk.RegisterWire(cdc)				//	Register	Msgs																											
				bank.RegisterWire(cdc)																																													
				stake.RegisterWire(cdc)																																												
				slashing.RegisterWire(cdc)																																									
				ibc.RegisterWire(cdc)																																														
				cdc.RegisterInterface((*auth.Account)(nil),	nil)	
				cdc.RegisterConcrete(&types.AppAccount{},	"basecoin/Account",	nil)	
				return	cdc	
}
cosmos-sdk/examples/basecoin/app/app.go
Lines 102 to 106 in d309abb
Register message routes
	app.Router().		
				AddRoute("auth",auth.NewHandler(	
									app.accountMapper)).		
				AddRoute("bank",	bank.NewHandler(	
									app.coinKeeper)).		
				AddRoute("ibc",	ibc.NewHandler(	
									app.ibcMapper,	app.coinKeeper)).		
				AddRoute("stake",	stake.NewHandler(	
									app.stakeKeeper))	
cosmos-sdk/examples/basecoin/app/app.go
Lines 78 to 83 in d309abb
EndBlocker
Process validator provisions
	//	XXX	assuming	in	seconds,	confirm		
	blockTime	:=	ctx.BlockHeader().Time		
	if	pool.InflationLastTime+blockTime	>=	3600	{		
				pool.InflationLastTime	=	blockTime		
				pool	=	k.processProvisions(ctx)		
	}	
cosmos-sdk/x/stake/handler.go
Lines 32 to 37 in 3fc7200
SDK - Staking Module
github.com/cosmos/cosmos-sdk/tree/
develop/x/stake
Learn more
tendermint.com
cosmos.network
We’re hiring!

More Related Content

PPTX
Curso de Node.js e MongoDB - 16
PDF
Workshop 23: ReactJS, React & Redux testing
PDF
Workshop 5: JavaScript testing
PDF
Bee Smalltalk RunTime: anchor's aweigh
PDF
PHP Enums - PHPCon Japan 2021
PDF
JavaScript Unit Testing with Jasmine
PDF
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
PDF
Workshop 10: ECMAScript 6
Curso de Node.js e MongoDB - 16
Workshop 23: ReactJS, React & Redux testing
Workshop 5: JavaScript testing
Bee Smalltalk RunTime: anchor's aweigh
PHP Enums - PHPCon Japan 2021
JavaScript Unit Testing with Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Workshop 10: ECMAScript 6

More from Tendermint Inc (11)

PDF
Cosmos SDK Workshop: How to Build a Blockchain from Scratch
PDF
Vision of Rearchitecting the Blockchain Ecosystem by Chjango Unchained
PPTX
Many Chains, Many Tokens, One Ecosystem
PDF
Open Finance & the Decentralization Movement
PDF
Introduction to Blockchain & Building the 3rd Generation with Golang
PDF
Interblockchain Communication for Blockchain Interoperability
PDF
A Brief History of Distributed State
PDF
Intro to the Cosmos Network
PDF
Four Dimensional Blockchain Scaling
PPTX
Cosmos Proof-of-Stake: An Introduction
PDF
Ethermint 2.0: An Ethereum Scaling Solution by Cosmos
Cosmos SDK Workshop: How to Build a Blockchain from Scratch
Vision of Rearchitecting the Blockchain Ecosystem by Chjango Unchained
Many Chains, Many Tokens, One Ecosystem
Open Finance & the Decentralization Movement
Introduction to Blockchain & Building the 3rd Generation with Golang
Interblockchain Communication for Blockchain Interoperability
A Brief History of Distributed State
Intro to the Cosmos Network
Four Dimensional Blockchain Scaling
Cosmos Proof-of-Stake: An Introduction
Ethermint 2.0: An Ethereum Scaling Solution by Cosmos
Ad

Recently uploaded (20)

PPT
Geologic Time for studying geology for geologist
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Architecture types and enterprise applications.pdf
PPTX
Modernising the Digital Integration Hub
PDF
CloudStack 4.21: First Look Webinar slides
PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
Hybrid model detection and classification of lung cancer
PDF
August Patch Tuesday
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Geologic Time for studying geology for geologist
Zenith AI: Advanced Artificial Intelligence
NewMind AI Weekly Chronicles – August ’25 Week III
Group 1 Presentation -Planning and Decision Making .pptx
Architecture types and enterprise applications.pdf
Modernising the Digital Integration Hub
CloudStack 4.21: First Look Webinar slides
Web Crawler for Trend Tracking Gen Z Insights.pptx
Assigned Numbers - 2025 - Bluetooth® Document
O2C Customer Invoices to Receipt V15A.pptx
Benefits of Physical activity for teenagers.pptx
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
A novel scalable deep ensemble learning framework for big data classification...
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Hybrid model detection and classification of lung cancer
August Patch Tuesday
Univ-Connecticut-ChatGPT-Presentaion.pdf
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Ad

Code Run of the Cosmos SDK