内容
数据格式和例子
理论上你可以往 Quorum 提交任意格式的数据。
为了不同应用之间的数据保持一致,从而可以互相通信,我们推荐使用的格式是 ActivityPub,知名的长毛象应用也是使用这个格式。
接下来我们通过各种各样的真实场景,制定数据格式并提交到 Quorum
创建文章
Javascript
Python
const SDK = require('rum-sdk-nodejs')
const group = SDK.cache.Group.add('rum://...')
SDK.chain.Trx.create({
data: {
type: 'Create',
object: {
type: 'Note',
id: '1',
content: 'hello world',
},
published: "2022-12-12T12:12:12Z",
},
groupId: group.groupId,
privateKey: '...',
})
// 上链之后的数据
{
"Data": {
"type": "Create",
"object": {
"type": "Note",
"id": "1",
"content": "hello world"
},
"published": "2022-12-12T12:12:12Z",
},
"TrxId": "...",
"GroupId": "...",
"Version": "2.0.0",
"TimeStamp" "1680526868853218300",
"SenderPubkey": "...",
"SenderSign": "..."
}
参考:ActivityPub#Create, ActivityPub#Note
创建带图片的文章
Javascript
Python
const SDK = require('rum-sdk-nodejs');
const group = SDK.cache.Group.add('rum://...');
SDK.chain.Trx.create({
data: {
type: "Create",
object : {
type: "Note",
id: "1",
content: "hello world",
image: [{
type: "Image",
name: "blue sky",
mediaType: "image/jpeg"
content: "data:image/jpeg;base64,/9j/4AA..."
}, {
type: "Image",
url: "https://example.org/cat.png"
}]
},
published: "2022-12-12T12:12:12Z",
},
groupId: group.groupId,
privateKey: '...'
});
// 上链之后的数据
{
"Data": {
"type": "Create",
"object" : {
"type": "Note",
"id": "1",
"content": "hello world",
"image": [{
"type": "Image",
"name": "blue sky",
"mediaType": "image/jpeg"
"content": "data:image/jpeg;base64,/9j/4AA..."
}, {
"type": "Image",
"url": "https://example.org/cat.png"
}]
},
"published": "2022-12-12T12:12:12Z",
},
"TrxId": "...",
"GroupId": "...",
"Version": "2.0.0",
"TimeStamp" "1680526868853218300",
"SenderPubkey": "...",
"SenderSign": "..."
}
参考:ActivityPub#Create, ActivityPub#Note, ActivityPub#Image
删除文章
Javascript
Python
const SDK = require('rum-sdk-nodejs')
const group = SDK.cache.Group.add('rum://...')
SDK.chain.Trx.create({
data: {
type: 'Delete',
object: {
type: 'Note',
id: '1',
},
published: "2022-12-12T12:12:12Z",
},
groupId: group.groupId,
privateKey: '...',
})
// 上链之后的数据
{
"Data": {
"type": "Delete",
"object": {
"type": "Note",
"id": "1"
},
"published": "2022-12-12T12:12:12Z",
},
"TrxId": "...",
"GroupId": "...",
"Version": "2.0.0",
"TimeStamp" "1680526868853218300",
"SenderPubkey": "...",
"SenderSign": "..."
}
更新文章
Javascript
Python
const SDK = require('rum-sdk-nodejs')
const group = SDK.cache.Group.add('rum://...')
SDK.chain.Trx.create({
data: {
type: 'Update',
object: {
type: 'Note',
id: '1',
},
result: {
type: 'Note',
content: 'hello world (edit)',
},
published: "2022-12-12T12:12:12Z",
},
groupId: group.groupId,
privateKey: '...',
})
// 上链之后的数据
{
"Data": {
"type": "Update",
"object": {
"type": "Note",
"id": "1"
},
"result": {
"type": "Note",
"content": "hello world (edit)"
},
"published": "2022-12-12T12:12:12Z",
},
"TrxId": "...",
"GroupId": "...",
"Version": "2.0.0",
"TimeStamp" "1680526868853218300",
"SenderPubkey": "...",
"SenderSign": "..."
}
点赞
Javascript
Python
const SDK = require('rum-sdk-nodejs')
const group = SDK.cache.Group.add('rum://...')
SDK.chain.Trx.create({
data: {
type: 'Like',
object: {
type: 'Note',
id: '1',
},
published: "2022-12-12T12:12:12Z",
},
groupId: group.groupId,
privateKey: '...',
})
// 上链之后的数据
{
"Data": {
"type": "Like",
"object": {
"type": "Note",
"id": "1"
},
"published": "2022-12-12T12:12:12Z",
},
"TrxId": "...",
"GroupId": "...",
"Version": "2.0.0",
"TimeStamp" "1680526868853218300",
"SenderPubkey": "...",
"SenderSign": "..."
}
取消点赞
Javascript
Python
const SDK = require('rum-sdk-nodejs')
const group = SDK.cache.Group.add('rum://...')
SDK.chain.Trx.create({
data: {
type: 'Undo',
object: {
type: 'Like',
object: {
type: 'Note',
id: '1',
},
},
published: "2022-12-12T12:12:12Z",
},
groupId: group.groupId,
privateKey: '...',
})
// 上链之后的数据
{
"Data": {
"type": "Undo",
"object": {
"type": "Like",
"object": {
"type": "Note",
"id": "1"
}
},
"published": "2022-12-12T12:12:12Z",
},
"TrxId": "...",
"GroupId": "...",
"Version": "2.0.0",
"TimeStamp" "1680526868853218300",
"SenderPubkey": "...",
"SenderSign": "..."
}
参考:ActivityPub#Undo, ActivityPub#Like
点踩
Javascript
Python
const SDK = require('rum-sdk-nodejs')
const group = SDK.cache.Group.add('rum://...')
SDK.chain.Trx.create({
data: {
type: 'Dislike',
object: {
type: 'Note',
id: '1',
},
published: "2022-12-12T12:12:12Z",
},
groupId: group.groupId,
privateKey: '...',
})
// 上链之后的数据
{
"Data": {
"type": "Dislike",
"object": {
"type": "Note",
"id": "1"
},
"published": "2022-12-12T12:12:12Z",
},
"TrxId": "...",
"GroupId": "...",
"Version": "2.0.0",
"TimeStamp" "1680526868853218300",
"SenderPubkey": "...",
"SenderSign": "..."
}
取消点踩
Javascript
Python
const SDK = require('rum-sdk-nodejs')
const group = SDK.cache.Group.add('rum://...')
SDK.chain.Trx.create({
data: {
type: 'Undo',
object: {
type: 'Dislike',
object: {
type: 'Note',
id: '1',
},
},
published: "2022-12-12T12:12:12Z",
},
groupId: group.groupId,
privateKey: '...',
})
// 上链之后的数据
{
"Data": {
"type": "Undo",
"object": {
"type": "Dislike",
"object": {
"type": "Note",
"id": "1"
}
},
"published": "2022-12-12T12:12:12Z",
},
"TrxId": "...",
"GroupId": "...",
"Version": "2.0.0",
"TimeStamp" "1680526868853218300",
"SenderPubkey": "...",
"SenderSign": "..."
}
参考:ActivityPub#Undo, ActivityPub#Dislike
评论
Javascript
Python
const SDK = require('rum-sdk-nodejs')
const group = SDK.cache.Group.add('rum://...')
SDK.chain.Trx.create({
data: {
type: 'Create',
object: {
type: 'Note',
id: '2',
content: 'awesome !!!',
inreplyto: {
type: 'Note',
id: '1',
},
},
published: "2022-12-12T12:12:12Z",
},
groupId: group.groupId,
privateKey: '...',
})
// 上链之后的数据
{
"Data": {
"type": "Create",
"object": {
"type": "Note",
"id": "2",
"content": "awesome !!!",
"inreplyto": {
"type": "Note",
"id": "1"
}
},
"published": "2022-12-12T12:12:12Z",
},
"TrxId": "...",
"GroupId": "...",
"Version": "2.0.0",
"TimeStamp" "1680526868853218300",
"SenderPubkey": "...",
"SenderSign": "..."
}
参考:ActivityPub#Create, ActivityPub#inreplyto
个人资料
Javascript
const SDK = require('rum-sdk-nodejs')
const group = SDK.cache.Group.add('rum://...')
SDK.chain.Trx.create({
data: {
type: 'Create',
object: {
type: 'Profile',
name: 'Jack',
image: {
type: "Image",
mediaType: "image/jpeg"
content: "data:image/jpeg;base64,/9j/4AA..."
},
describes: {
type: 'Person',
id: 'user eth address',
},
},
published: "2022-12-12T12:12:12Z",
},
groupId: group.groupId,
privateKey: '...',
})
// 上链之后的数据
{
"Data": {
"type": "Create",
"object": {
"type": "Profile",
"name": "Jack",
"image": {
"type": "Image",
"mediaType": "image/jpeg",
"content": "data:image/jpeg;base64,/9j/4AA..."
},
"describes": {
"type": "Person",
"id": "user eth address"
}
},
"published": "2022-12-12T12:12:12Z",
},
"TrxId": "...",
"GroupId": "...",
"Version": "2.0.0",
"TimeStamp" "1680526868853218300",
"SenderPubkey": "...",
"SenderSign": "..."
}
参考:ActivityPub#Create, ActivityPub#Profile
转发
Javascript
const SDK = require('rum-sdk-nodejs')
const group = SDK.cache.Group.add('rum://...')
SDK.chain.Trx.create({
data: {
type: 'Create',
object: {
type: 'Note',
id: '2',
content: 'Awesome 👇👇',
object: {
type: 'Note',
id: '1',
},
},
published: "2022-12-12T12:12:12Z",
},
groupId: group.groupId,
privateKey: '...',
})
// 上链之后的数据
{
"Data": {
"type": "Create",
"object": {
"type": "Note",
"id": "2",
"content": "Awesome 👇👇",
"object": {
"type": "Note",
"id": "1",
},
},
"published": "2022-12-12T12:12:12Z",
},
"TrxId": "...",
"GroupId": "...",
"Version": "2.0.0",
"TimeStamp" "1680526868853218300",
"SenderPubkey": "...",
"SenderSign": "..."
}
关注
Javascript
const SDK = require('rum-sdk-nodejs')
const group = SDK.cache.Group.add('rum://...')
SDK.chain.Trx.create({
data: {
type: 'Follow',
object: {
type: 'Person',
id: 'user eth address',
},
published: "2022-12-12T12:12:12Z",
},
groupId: group.groupId,
privateKey: '...',
})
// 上链之后的数据
{
"Data": {
"type": "Follow",
"object": {
"type": "Person",
"id": "user eth address"
},
"published": "2022-12-12T12:12:12Z",
},
"TrxId": "...",
"GroupId": "...",
"Version": "2.0.0",
"TimeStamp" "1680526868853218300",
"SenderPubkey": "...",
"SenderSign": "..."
}
参考:ActivityPub#Follow, ActivityPub#Person
取消关注
Javascript
const SDK = require('rum-sdk-nodejs')
const group = SDK.cache.Group.add('rum://...')
SDK.chain.Trx.create({
data: {
type: 'Undo',
object: {
type: 'Follow',
object: {
type: 'Person',
id: 'user eth address',
},
},
published: "2022-12-12T12:12:12Z",
},
groupId: group.groupId,
privateKey: '...',
})
// 上链之后的数据
{
"Data": {
"type": "Undo",
"object": {
"type": "Follow",
"object": {
"type": "Person",
"id": "user eth address"
}
},
"published": "2022-12-12T12:12:12Z",
},
"TrxId": "...",
"GroupId": "...",
"Version": "2.0.0",
"TimeStamp" "1680526868853218300",
"SenderPubkey": "...",
"SenderSign": "..."
}
参考:ActivityPub#Undo, ActivityPub#Follow, ActivityPub#Person
屏蔽
Javascript
const SDK = require('rum-sdk-nodejs')
const group = SDK.cache.Group.add('rum://...')
SDK.chain.Trx.create({
data: {
type: 'Block',
object: {
type: 'Person',
id: 'user eth address',
},
published: "2022-12-12T12:12:12Z",
},
groupId: group.groupId,
privateKey: '...',
})
// 上链之后的数据
{
"Data": {
"type": "Block",
"object": {
"type": "Person",
"id": "user eth address"
},
"published": "2022-12-12T12:12:12Z",
},
"TrxId": "...",
"GroupId": "...",
"Version": "2.0.0",
"TimeStamp" "1680526868853218300",
"SenderPubkey": "...",
"SenderSign": "..."
}
参考:ActivityPub#Block, ActivityPub#Person
取消屏蔽
Javascript
const SDK = require('rum-sdk-nodejs')
const group = SDK.cache.Group.add('rum://...')
SDK.chain.Trx.create({
data: {
type: 'Undo',
object: {
type: 'Block',
object: {
type: 'Person',
id: 'user eth address',
},
},
published: "2022-12-12T12:12:12Z",
},
groupId: group.groupId,
privateKey: '...',
})
// 上链之后的数据
{
"Data": {
"type": "Undo",
"object": {
"type": "Block",
"object": {
"type": "Person",
"id": "user eth address"
}
},
"published": "2022-12-12T12:12:12Z",
},
"TrxId": "...",
"GroupId": "...",
"Version": "2.0.0",
"TimeStamp" "1680526868853218300",
"SenderPubkey": "...",
"SenderSign": "..."
}