share

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2017 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CardPrototypes = map[int]CardPrototype{
	0:  CardPrototype{ID: 0, Name: "Zero", Lines: "我是开始,我是结束,我是阿赖耶,我是真理之门,我是一切的根源,我,是Zero", Rarity: 5},
	27: CardPrototype{ID: 27, Name: "42", Lines: "宇宙的奥秘,从此揭开", Rarity: 5},

	1:  CardPrototype{ID: 1, Name: "新桓结衣", Lines: "我不是你的老婆", Rarity: 4},
	26: CardPrototype{ID: 26, Name: "樱宁宁", Lines: "CPP又崩溃啦", Rarity: 4},

	2: CardPrototype{ID: 2, Name: "《计算机程序的构造和解释》(SICP)", Lines: "做完我的习题,再说你读过", Rarity: 4},
	3: CardPrototype{ID: 3, Name: "《黑客与画家》", Lines: "先实现一门语言,然后再开始实现功能。", Rarity: 4},
	4: CardPrototype{ID: 4, Name: "《代码大全》", Lines: "在挡子弹这件事情上,我很有自信", Rarity: 4},
	5: CardPrototype{ID: 5, Name: "《设计模式》", Lines: "四老外激动地站了起来", Rarity: 4},
	6: CardPrototype{ID: 6, Name: "《Unix网络编程》", Lines: "万物皆文件", Rarity: 4},
	7: CardPrototype{ID: 7, Name: "《TCP/IP详解》", Lines: "01111110", Rarity: 4},
	8: CardPrototype{ID: 8, Name: "《重构》", Lines: "写好测试,敏捷的重构你的微服务吧", Rarity: 3},
	9: CardPrototype{ID: 9, Name: "《编译原理技术和工具》", Lines: "屠龙之术不在乎有无龙可屠", Rarity: 4},

	10: CardPrototype{ID: 10, Name: "《C++ Primer》", Lines: "上个号称要七天精通C++的人造出了时光机", Rarity: 3},
	11: CardPrototype{ID: 11, Name: "《Python基础教程》", Lines: "人生苦短,我用大蟒蛇", Rarity: 3},
	12: CardPrototype{ID: 12, Name: "《Thinking in Java》", Lines: "老铁,来杯爪哇咖啡么", Rarity: 3},
	13: CardPrototype{ID: 13, Name: "《七天学会HTML》", Lines: "HTML是宇宙最好的语言", Rarity: 3},
	14: CardPrototype{ID: 14, Name: "《MYSQL从入门到跑路》", Lines: "DROP TABLE users;", Rarity: 3},
	15: CardPrototype{ID: 15, Name: "《React中文指南》", Lines: "尤雨溪给你多少钱?我马克扎波给你双倍", Rarity: 3},
	16: CardPrototype{ID: 16, Name: "《PHP和MySQL Web开发》", Lines: "我不是针对谁,我是说...", Rarity: 3},
	17: CardPrototype{ID: 17, Name: "《Web开发敏捷之道》", Lines: "听说硅谷的红宝石必须跑在轨道上", Rarity: 3},
	18: CardPrototype{ID: 18, Name: "《从0到1》", Lines: "作为村里唯一可以卖意大利炒面的餐馆,在几万亿的餐饮市场里我所向无敌", Rarity: 3},
	19: CardPrototype{ID: 19, Name: "《禅与摩托车维修艺术》", Lines: "你们程序员能不能不要再围观我修车了,该死,我说的是摩托车", Rarity: 3},

	20: CardPrototype{ID: 20, Name: "《复变函数》", Lines: "正在对你进行傅里叶展开", Rarity: 4},
	21: CardPrototype{ID: 21, Name: "《线性代数》", Lines: "He is the one", Rarity: 4},
	22: CardPrototype{ID: 22, Name: "《微积分学教程》", Lines: "抑制了房价快速上涨的趋势", Rarity: 4},
	23: CardPrototype{ID: 23, Name: "《数学分析》", Lines: "少年,你渴望力量吗?", Rarity: 4},
	24: CardPrototype{ID: 24, Name: "《实变函数》", Lines: "少年,你渴望力量吗?", Rarity: 4},
	25: CardPrototype{ID: 25, Name: "《泛函分析》", Lines: "少年,你渴望力量吗?", Rarity: 4},
}

CardPrototypes 是卡片列表 卡片ID是算法是[0-9] + [0-9] + [0-9] 最小为0,最大为27 0和27最稀有,越靠近两边越稀有

Functions

func CardBlockToMsg

func CardBlockToMsg(block *CardBlock) *cardproto.CardBlock

CardBlockToMsg 从区块到消息

func GenerateRSAKeys

func GenerateRSAKeys() *rsa.PrivateKey

GenerateRSAKeys 生成RSA钥匙对

func GetKeyPair

func GetKeyPair() *rsa.PrivateKey

GetKeyPair 从磁盘获取密钥,如果得不到就重新生成

func GetKeyPairFromDisk

func GetKeyPairFromDisk() (*rsa.PrivateKey, error)

GetKeyPairFromDisk 从磁盘获得钥匙的对象。实际上只读私钥就行了

func Load

func Load(data interface{}, filename string)

Load 从文件读区块

func LoadFromRaw

func LoadFromRaw(data interface{}, raw []byte)

LoadFromRaw 从二进制流读区块

func LoadPrivateKeyFromDisk

func LoadPrivateKeyFromDisk() (*rsa.PrivateKey, error)

LoadPrivateKeyFromDisk 我今天才知道,私钥可以算公钥,有私钥删掉公钥都行

func LoadPublicKeyFromDisk

func LoadPublicKeyFromDisk() (*rsa.PublicKey, error)

LoadPublicKeyFromDisk 从磁盘读公钥

func LoadPublicKeyFromString

func LoadPublicKeyFromString(key string) (*rsa.PublicKey, error)

LoadPublicKeyFromString 从string读公钥

func PubKey

func PubKey(key *rsa.PrivateKey) string

PubKey 返回公钥的string,要填写在区块用的

func Store

func Store(data interface{}, filename string)

Store 存bin

Types

type Card

type Card struct {
	ID      int
	Attack  int
	Defense int
	CardID  string
}

Card is CardBlock helper

type CardBlock

type CardBlock struct {
	Version    string
	Hard       int32
	PubKey     string
	Timestamp  int64
	RandNumber int32
	PrevCardID string
	Height     int64
}

CardBlock 卡区块

func LoadCard

func LoadCard(filePath string) CardBlock

LoadCard json to CardBlock

func ProtoToBlock

func ProtoToBlock(msg *cardproto.CardBlock) *CardBlock

ProtoToBlock 从消息到区块

func PushProtoToBlock

func PushProtoToBlock(msg *cardproto.CardBlockPushRequest) *CardBlock

PushProtoToBlock 解析提交区块消息

func (*CardBlock) Build

func (card *CardBlock) Build() string

Build 构建一张卡

func (CardBlock) Card

func (card CardBlock) Card() (Card, error)

Card 分析区块包含的卡

func (*CardBlock) CardID

func (card *CardBlock) CardID() string

CardID 获取区块的ID

func (CardBlock) Cid

func (card CardBlock) Cid() (int, error)

Cid 分析区块的卡片id

func (CardBlock) Cut

func (card CardBlock) Cut(from int, to int) string

Cut 切区块字符串

func (*CardBlock) HardInt

func (card *CardBlock) HardInt() int

HardInt 返回int

func (*CardBlock) JSON

func (card *CardBlock) JSON() string

JSON 区块json

func (*CardBlock) Verify

func (card *CardBlock) Verify() bool

Verify 验证是否为真卡

func (*CardBlock) VerifyCardID

func (card *CardBlock) VerifyCardID() bool

VerifyCardID 验证卡片id,也就是验证区块是不是真的

type CardBlockChain

type CardBlockChain struct {
	Cardblocks []*CardBlock
}

CardBlockChain 区块链

func LoadCardBlockChainFromDisk

func LoadCardBlockChainFromDisk(path string) *CardBlockChain

LoadCardBlockChainFromDisk 从文件读取历史区块

func (*CardBlockChain) AdaptiveHard

func (chain *CardBlockChain) AdaptiveHard() int32

AdaptiveHard 根据之前区块被挖掘的速度去调整新块产生的速度 一分钟出块,如果低于一分钟就加难度,高于两分钟就减难度 无上限,无减半

func (*CardBlockChain) BlockAtHeight

func (chain *CardBlockChain) BlockAtHeight(height int64) (*CardBlock, error)

BlockAtHeight 获取特定高度的区块

func (*CardBlockChain) HeadBlock

func (chain *CardBlockChain) HeadBlock() *CardBlock

HeadBlock 最后一个块

func (*CardBlockChain) Height

func (chain *CardBlockChain) Height() int64

Height 区块链高度

type CardPrototype

type CardPrototype struct {
	ID     int
	Name   string
	Lines  string
	Rarity int
}

CardPrototype 是card的原型

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL