mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
add first draft of protobuf entities
This commit is contained in:
parent
a5d08d90dd
commit
9f4ce35edc
8
dlt-connector/src/graphql/enum/AddressType.ts
Normal file
8
dlt-connector/src/graphql/enum/AddressType.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export enum AddressType {
|
||||
NONE = 0, // if no address was found
|
||||
HUMAN = 1,
|
||||
PROJECT = 2, // no creations allowed
|
||||
SUBACCOUNT = 3, // no creations allowed
|
||||
CRYPTO_ACCOUNT = 4, // user control his keys, no creations
|
||||
COMMUNITY_ACCOUNT = 5, // community control keys, creations allowed
|
||||
}
|
||||
7
dlt-connector/src/graphql/enum/CrossGroupType.ts
Normal file
7
dlt-connector/src/graphql/enum/CrossGroupType.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export enum CrossGroupType {
|
||||
LOCAL = 0,
|
||||
INBOUND = 1,
|
||||
OUTBOUND = 2,
|
||||
// for cross group transaction which haven't a direction like group friend update
|
||||
CROSS = 3,
|
||||
}
|
||||
16
dlt-connector/src/proto/GradidoCreation.ts
Normal file
16
dlt-connector/src/proto/GradidoCreation.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { Field, Message } from '@apollo/protobufjs'
|
||||
|
||||
import { TimestampSeconds } from './TimestampSeconds'
|
||||
import { TransferAmount } from './TransferAmount'
|
||||
|
||||
// need signature from group admin or
|
||||
// percent of group users another than the receiver
|
||||
// https://www.npmjs.com/package/@apollo/protobufjs
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
export class GradidoCreation extends Message<GradidoCreation> {
|
||||
@Field.d(1, TransferAmount)
|
||||
public recipient: TransferAmount
|
||||
|
||||
@Field.d(3, 'TimestampSeconds')
|
||||
public targetDate: TimestampSeconds
|
||||
}
|
||||
31
dlt-connector/src/proto/GradidoDeferredTransfer.ts
Normal file
31
dlt-connector/src/proto/GradidoDeferredTransfer.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { Field, Message } from '@apollo/protobufjs'
|
||||
|
||||
import { GradidoTransfer } from './GradidoTransfer'
|
||||
import { Timestamp } from './Timestamp'
|
||||
|
||||
// transaction type for chargeable transactions
|
||||
// for transaction for people which haven't a account already
|
||||
// consider using a seed number for key pair generation for recipient
|
||||
// using seed as redeem key for claiming transaction, technically make a default Transfer transaction from recipient address
|
||||
// seed must be long enough to prevent brute force, maybe base64 encoded
|
||||
// to own account
|
||||
// https://www.npmjs.com/package/@apollo/protobufjs
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
export class GradidoDeferredTransfer extends Message<GradidoDeferredTransfer> {
|
||||
// amount is amount with decay for time span between transaction was received and timeout
|
||||
// useable amount can be calculated
|
||||
// recipient address don't need to be registered in blockchain with register address
|
||||
@Field.d(1, GradidoTransfer)
|
||||
public transfer: GradidoTransfer
|
||||
|
||||
// if timeout timestamp is reached if it wasn't used, it will be booked back minus decay
|
||||
// technically on blockchain no additional transaction will be created because how should sign it?
|
||||
// the decay for amount and the seconds until timeout is lost no matter what happened
|
||||
// consider is as fee for this service
|
||||
// rest decay could be transferred back as separate transaction
|
||||
@Field.d(2, 'Timestamp')
|
||||
public timeout: Timestamp
|
||||
|
||||
// split for n recipient
|
||||
// max gradido per recipient? or per transaction with cool down?
|
||||
}
|
||||
21
dlt-connector/src/proto/GradidoTransaction.ts
Normal file
21
dlt-connector/src/proto/GradidoTransaction.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { Field, Message } from '@apollo/protobufjs'
|
||||
|
||||
import { SignatureMap } from './SignatureMap'
|
||||
|
||||
// https://www.npmjs.com/package/@apollo/protobufjs
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
export class GradidoTransaction extends Message<GradidoTransaction> {
|
||||
@Field.d(1, SignatureMap)
|
||||
public sigMap: SignatureMap
|
||||
|
||||
// inspired by Hedera
|
||||
// bodyBytes are the payload for signature
|
||||
// bodyBytes are serialized TransactionBody
|
||||
@Field.d(2, 'bytes')
|
||||
public bodyBytes: Buffer
|
||||
|
||||
// if it is a cross group transaction the parent message
|
||||
// id from outbound transaction or other by cross
|
||||
@Field.d(3, 'bytes')
|
||||
public parentMessageId: Buffer
|
||||
}
|
||||
13
dlt-connector/src/proto/GradidoTransfer.ts
Normal file
13
dlt-connector/src/proto/GradidoTransfer.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { Field, Message } from '@apollo/protobufjs'
|
||||
|
||||
import { TransferAmount } from './TransferAmount'
|
||||
|
||||
// https://www.npmjs.com/package/@apollo/protobufjs
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
export class GradidoTransfer extends Message<GradidoTransfer> {
|
||||
@Field.d(1, TransferAmount)
|
||||
public sender: TransferAmount
|
||||
|
||||
@Field.d(2, 'bytes')
|
||||
public recipient: Buffer
|
||||
}
|
||||
15
dlt-connector/src/proto/GroupFriendsUpdate.ts
Normal file
15
dlt-connector/src/proto/GroupFriendsUpdate.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { Field, Message } from '@apollo/protobufjs'
|
||||
|
||||
// connect group together
|
||||
// only CrossGroupType CROSS (in TransactionBody)
|
||||
// https://www.npmjs.com/package/@apollo/protobufjs
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
export class GroupFriendsUpdate extends Message<GroupFriendsUpdate> {
|
||||
// if set to true, colors of this both groups are trait as the same
|
||||
// on creation user get coins still in there color
|
||||
// on transfer into another group which a connection exist,
|
||||
// coins will be automatic swapped into user group color coin
|
||||
// (if fusion between src coin and dst coin is enabled)
|
||||
@Field.d(1, 'bool')
|
||||
public colorFusion: boolean
|
||||
}
|
||||
19
dlt-connector/src/proto/RegisterAddress.ts
Normal file
19
dlt-connector/src/proto/RegisterAddress.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { Field, Message } from '@apollo/protobufjs'
|
||||
|
||||
import { AddressType } from '@enum/AddressType'
|
||||
|
||||
// https://www.npmjs.com/package/@apollo/protobufjs
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
export class RegisterAddress extends Message<RegisterAddress> {
|
||||
@Field.d(1, 'bytes')
|
||||
public userPubkey: Buffer
|
||||
|
||||
@Field.d(2, 'AddressType')
|
||||
public addressType: AddressType
|
||||
|
||||
@Field.d(3, 'bytes')
|
||||
public nameHash: Buffer
|
||||
|
||||
@Field.d(4, 'bytes')
|
||||
public subaccountPubkey: Buffer
|
||||
}
|
||||
10
dlt-connector/src/proto/SignatureMap.ts
Normal file
10
dlt-connector/src/proto/SignatureMap.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { Field, Message } from '@apollo/protobufjs'
|
||||
|
||||
import { SignaturePair } from './SignaturePair'
|
||||
|
||||
// https://www.npmjs.com/package/@apollo/protobufjs
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
export class SignatureMap extends Message<SignatureMap> {
|
||||
@Field.d(1, SignaturePair, 'repeated')
|
||||
public sigPair: SignaturePair
|
||||
}
|
||||
11
dlt-connector/src/proto/SignaturePair.ts
Normal file
11
dlt-connector/src/proto/SignaturePair.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Field, Message } from '@apollo/protobufjs'
|
||||
|
||||
// https://www.npmjs.com/package/@apollo/protobufjs
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
export class SignaturePair extends Message<SignaturePair> {
|
||||
@Field.d(1, 'bytes')
|
||||
public pubKey: Buffer
|
||||
|
||||
@Field.d(2, 'bytes')
|
||||
public signature: Buffer
|
||||
}
|
||||
13
dlt-connector/src/proto/Timestamp.ts
Normal file
13
dlt-connector/src/proto/Timestamp.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { Field, Message } from '@apollo/protobufjs'
|
||||
|
||||
// https://www.npmjs.com/package/@apollo/protobufjs
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
export class Timestamp extends Message<Timestamp> {
|
||||
// Number of complete seconds since the start of the epoch
|
||||
@Field.d(1, 'int64')
|
||||
public seconds: number
|
||||
|
||||
// Number of nanoseconds since the start of the last second
|
||||
@Field.d(2, 'int32')
|
||||
public nanoSeconds: number
|
||||
}
|
||||
9
dlt-connector/src/proto/TimestampSeconds.ts
Normal file
9
dlt-connector/src/proto/TimestampSeconds.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { Field, Message } from '@apollo/protobufjs'
|
||||
|
||||
// https://www.npmjs.com/package/@apollo/protobufjs
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
export class TimestampSeconds extends Message<TimestampSeconds> {
|
||||
// Number of complete seconds since the start of the epoch
|
||||
@Field.d(1, 'int64')
|
||||
public seconds: number
|
||||
}
|
||||
@ -3,25 +3,27 @@ import { TransactionType } from '@enum/TransactionType'
|
||||
import { TransactionInput } from '@input/TransactionInput'
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { TransactionBody } from './TransactionBody'
|
||||
import { TimestampSeconds } from './TimestampSeconds'
|
||||
|
||||
describe('proto/TransactionBodyTest', () => {
|
||||
it('test compatible with graphql/input/TransactionInput', async () => {
|
||||
// test data
|
||||
const type = TransactionType.SEND
|
||||
const amount = new Decimal('10')
|
||||
const createdAt = 1688992436
|
||||
const createdAt = new TimestampSeconds()
|
||||
createdAt.seconds = 1688992436
|
||||
|
||||
// init both objects
|
||||
// graphql input object
|
||||
const transactionInput = new TransactionInput()
|
||||
transactionInput.type = type
|
||||
transactionInput.amount = amount
|
||||
transactionInput.createdAt = createdAt
|
||||
transactionInput.createdAt = createdAt.seconds
|
||||
|
||||
// protobuf object
|
||||
const transactionBody = new TransactionBody()
|
||||
transactionBody.type = type
|
||||
transactionBody.amount = amount.toString()
|
||||
// transactionBody.type = type
|
||||
// transactionBody.amount = amount.toString()
|
||||
transactionBody.createdAt = createdAt
|
||||
|
||||
// create protobuf object from graphql Input object
|
||||
|
||||
@ -1,18 +1,60 @@
|
||||
import { TransactionType } from '../graphql/enum/TransactionType'
|
||||
import { Field, Message } from '@apollo/protobufjs'
|
||||
import { Field, Message, OneOf } from '@apollo/protobufjs'
|
||||
|
||||
import { CrossGroupType } from '@/graphql/enum/CrossGroupType'
|
||||
|
||||
import { TimestampSeconds } from './TimestampSeconds'
|
||||
import { GradidoTransfer } from './GradidoTransfer'
|
||||
import { GradidoCreation } from './GradidoCreation'
|
||||
import { GradidoDeferredTransfer } from './GradidoDeferredTransfer'
|
||||
import { GroupFriendsUpdate } from './GroupFriendsUpdate'
|
||||
import { RegisterAddress } from './RegisterAddress'
|
||||
|
||||
/*interface OneofExample {
|
||||
result:
|
||||
| { oneofKind: 'value'; value: number }
|
||||
| { oneofKind: 'error'; error: string }
|
||||
| { oneofKind: undefined }
|
||||
}*/
|
||||
|
||||
// https://www.npmjs.com/package/@apollo/protobufjs
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
export class TransactionBody extends Message<TransactionBody> {
|
||||
@Field.d(1, TransactionType)
|
||||
type: TransactionType
|
||||
@Field.d(1, 'string')
|
||||
public memo: string
|
||||
|
||||
@Field.d(2, 'string')
|
||||
amount: string
|
||||
@Field.d(2, TimestampSeconds)
|
||||
public createdAt: TimestampSeconds
|
||||
|
||||
@Field.d(3, 'uint64')
|
||||
createdAt: number
|
||||
@Field.d(3, 'string')
|
||||
public versionNumber: string
|
||||
|
||||
// @protoField.d(4, 'string')
|
||||
// communitySum: Decimal
|
||||
@Field.d(4, CrossGroupType)
|
||||
public type: CrossGroupType
|
||||
|
||||
@Field.d(5, 'string')
|
||||
public otherGroup: string
|
||||
|
||||
@OneOf.d(
|
||||
'gradidoTransfer',
|
||||
'gradidoCreation',
|
||||
'groupFriendsUpdate',
|
||||
'registerAddress',
|
||||
'gradidoDeferredTransfer',
|
||||
)
|
||||
public data: string
|
||||
|
||||
@Field.d(6, 'GradidoTransfer')
|
||||
transfer?: GradidoTransfer
|
||||
|
||||
@Field.d(7, 'GradidoCreation')
|
||||
creation?: GradidoCreation
|
||||
|
||||
@Field.d(8, 'GroupFriendsUpdate')
|
||||
groupFriendsUpdate?: GroupFriendsUpdate
|
||||
|
||||
@Field.d(9, 'RegisterAddress')
|
||||
registerAddress?: RegisterAddress
|
||||
|
||||
@Field.d(10, 'GradidoDeferredTransfer')
|
||||
deferredTransfer?: GradidoDeferredTransfer
|
||||
}
|
||||
|
||||
16
dlt-connector/src/proto/TransferAmount.ts
Normal file
16
dlt-connector/src/proto/TransferAmount.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { Field, Message } from '@apollo/protobufjs'
|
||||
|
||||
// https://www.npmjs.com/package/@apollo/protobufjs
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
export class TransferAmount extends Message<TransferAmount> {
|
||||
@Field.d(1, 'bytes')
|
||||
public pubkey: Buffer
|
||||
|
||||
@Field.d(2, 'string')
|
||||
public amount: string
|
||||
|
||||
// community which created this coin
|
||||
// used for colored coins
|
||||
@Field.d(3, 'string')
|
||||
public communityId: string
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user