Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
smartcontracts
transactionCC
Commits
ae71aee0
Commit
ae71aee0
authored
6 years ago
by
Yury
Browse files
Options
Download
Plain Diff
Merge branch 'feature/rub_usd' into 'dev'
Feature/rub usd See merge request
!45
parents
4f404b00
0bfa80d7
feature/init_rename_to_configure
dev-27-02-18-06
Release-1.3.1_couch
1 merge request
!45
Feature/rub usd
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
vendor/gitlab.smartblocklab.com/smartcontracts/common/chaincode/PingData.go
+4
-0
...tblocklab.com/smartcontracts/common/chaincode/PingData.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/chaincode/imanager.go
+4
-0
...tblocklab.com/smartcontracts/common/chaincode/imanager.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/chaincode/manager.go
+52
-4
...rtblocklab.com/smartcontracts/common/chaincode/manager.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/chaincode/mock_manager.go
+20
-0
...cklab.com/smartcontracts/common/chaincode/mock_manager.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/chaincode/model.go
+25
-0
...martblocklab.com/smartcontracts/common/chaincode/model.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/chaincode/valid_object.go
+1
-0
...cklab.com/smartcontracts/common/chaincode/valid_object.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/invoke/keyValueCC.go
+2
-0
...rtblocklab.com/smartcontracts/common/invoke/keyValueCC.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/accountCC/Account_data.go
+4
-0
...com/smartcontracts/common/model/accountCC/Account_data.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/accountCC/Wallet_data.go
+4
-0
....com/smartcontracts/common/model/accountCC/Wallet_data.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/commissionCC/Commission_data.go
+4
-0
...artcontracts/common/model/commissionCC/Commission_data.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/cryptocurrencyCC/CryptocurrencyStore_data.go
+4
-0
...common/model/cryptocurrencyCC/CryptocurrencyStore_data.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/marketCC/MarketTransaction_data.go
+4
-0
...contracts/common/model/marketCC/MarketTransaction_data.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/offerCC/OfferRequest_data.go
+4
-0
.../smartcontracts/common/model/offerCC/OfferRequest_data.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/organizationCC/Organization_data.go
+4
-0
...ontracts/common/model/organizationCC/Organization_data.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/preferenceCC/Preference_data.go
+4
-0
...artcontracts/common/model/preferenceCC/Preference_data.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/requests/Id_data.go
+10
-0
...cklab.com/smartcontracts/common/model/requests/Id_data.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/transactionCC/TransactionRecord_data.go
+4
-0
...acts/common/model/transactionCC/TransactionRecord_data.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/userCC/User_data.go
+4
-0
...cklab.com/smartcontracts/common/model/userCC/User_data.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/userPreferenceCC/UserPreference_data.go
+4
-0
...acts/common/model/userPreferenceCC/UserPreference_data.go
vendor/gitlab.smartblocklab.com/smartcontracts/common/nums/currency.go
+7
-0
....smartblocklab.com/smartcontracts/common/nums/currency.go
with
169 additions
and
4 deletions
+169
-4
vendor/gitlab.smartblocklab.com/smartcontracts/common/chaincode/PingData.go
View file @
ae71aee0
...
...
@@ -10,6 +10,10 @@ type PingRecord struct {
Value
string
`json:"value,omitempty"`
}
func
(
this
PingRecord
)
GetObjectType
()
string
{
return
"PingRecord"
;
}
func
(
this
PingRecord
)
CheckBeforeAdd
(
manager
IManager
)
error
{
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/chaincode/imanager.go
View file @
ae71aee0
...
...
@@ -7,6 +7,10 @@ import (
type
IManager
interface
{
GetTime
()
int64
GetStateByPartialCompositeKey
(
objectType
string
,
keys
[]
string
)
(
shim
.
StateQueryIteratorInterface
,
error
)
CreateCompositeKey
(
objectType
string
,
attributes
[]
string
)
(
string
,
error
)
GetObjectListByPartialCompositeKey
(
expectedValidObjectType
ValidObject
,
keys
[]
string
)
([]
ValidObject
,
error
)
SplitCompositeKey
(
compositeKey
string
)
(
string
,
[]
string
,
error
)
SetAdapter
(
new
StubInterfaceAdapter
)
SetTimeGetter
(
new
TimeGetter
)
GetAdapter
()
StubInterfaceAdapter
...
...
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/chaincode/manager.go
View file @
ae71aee0
package
chaincode
import
(
"encoding/json"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb
"github.com/hyperledger/fabric/protos/peer"
"encoding/json"
"github.com/pkg/errors"
"reflect"
"gitlab.smartblocklab.com/smartcontracts/common/security/actions"
"gitlab.smartblocklab.com/smartcontracts/common/model/requests"
"gitlab.smartblocklab.com/smartcontracts/common/invoke"
"gitlab.smartblocklab.com/smartcontracts/common/model/requests"
"gitlab.smartblocklab.com/smartcontracts/common/security/actions"
"reflect"
)
// Пример наследования данной структуры
...
...
@@ -68,6 +68,54 @@ func (this ManagerImpl) PutState(key string, value []byte) error {
return
this
.
Adapter
.
PutState
(
key
,
value
)
}
func
(
this
ManagerImpl
)
CreateCompositeKey
(
objectType
string
,
attributes
[]
string
)
(
string
,
error
)
{
GlobalLogger
.
Infof
(
"managerImpl.CreateCompositeKey by objectType %s and attributes %v"
,
objectType
,
attributes
)
return
this
.
Adapter
.
CreateCompositeKey
(
objectType
,
attributes
)
}
func
(
this
ManagerImpl
)
GetStateByPartialCompositeKey
(
objectType
string
,
keys
[]
string
)
(
shim
.
StateQueryIteratorInterface
,
error
)
{
GlobalLogger
.
Infof
(
"managerImpl.CreateCompositeKey by objectType %s and attributes %v"
,
objectType
,
keys
)
return
this
.
Adapter
.
GetStateByPartialCompositeKey
(
objectType
,
keys
)
}
func
(
this
ManagerImpl
)
GetObjectListByPartialCompositeKey
(
expectedValidObjectType
ValidObject
,
keys
[]
string
)
([]
ValidObject
,
error
)
{
objectType
:=
expectedValidObjectType
.
GetObjectType
()
GlobalLogger
.
Infof
(
"managerImpl.CreateCompositeKey by objectType %s and attributes %v"
,
objectType
,
keys
)
stateQueryIteratorInterface
,
err
:=
this
.
GetStateByPartialCompositeKey
(
objectType
,
keys
)
if
err
!=
nil
{
return
nil
,
err
}
defer
stateQueryIteratorInterface
.
Close
()
validObjectArray
:=
[]
ValidObject
{}
// Iterate through result set and for each marble found, transfer to newOwner
var
i
int
for
i
=
0
;
stateQueryIteratorInterface
.
HasNext
();
i
++
{
// Note that we don't get the value (2nd return variable), we'll just get the marble name from the composite key
responseRange
,
err
:=
stateQueryIteratorInterface
.
Next
()
if
err
!=
nil
{
return
nil
,
err
}
validObject
:=
expectedValidObjectType
.
New
()
err
=
json
.
Unmarshal
(
responseRange
.
Value
,
validObject
)
if
err
!=
nil
{
return
nil
,
GlobalLogger
.
Error
(
err
.
Error
())
}
validObjectArray
=
append
(
validObjectArray
,
validObject
)
}
return
validObjectArray
,
nil
}
func
(
this
ManagerImpl
)
SplitCompositeKey
(
compositeKey
string
)
(
string
,
[]
string
,
error
)
{
GlobalLogger
.
Infof
(
"managerImpl.SplitCompositeKey by key %s"
,
compositeKey
)
return
this
.
Adapter
.
SplitCompositeKey
(
compositeKey
)
}
func
(
this
ManagerImpl
)
DelState
(
key
string
)
error
{
GlobalLogger
.
Infof
(
"managerImpl.DelState %s"
,
key
)
return
this
.
Adapter
.
DelState
(
key
)
...
...
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/chaincode/mock_manager.go
View file @
ae71aee0
...
...
@@ -68,6 +68,26 @@ func (mock ManagerImplMock) GetQueryResult(query string) (shim.StateQueryIterato
return
mockArgs
.
Get
(
0
)
.
(
shim
.
StateQueryIteratorInterface
),
mockArgs
.
Error
(
1
)
}
func
(
mock
ManagerImplMock
)
GetStateByPartialCompositeKey
(
objectType
string
,
keys
[]
string
)
(
shim
.
StateQueryIteratorInterface
,
error
)
{
mockArgs
:=
mock
.
Called
(
objectType
,
keys
)
return
mockArgs
.
Get
(
0
)
.
(
shim
.
StateQueryIteratorInterface
),
mockArgs
.
Error
(
1
)
}
func
(
mock
ManagerImplMock
)
GetObjectListByPartialCompositeKey
(
expectedValidObjectType
ValidObject
,
keys
[]
string
)
([]
ValidObject
,
error
)
{
mockArgs
:=
mock
.
Called
(
expectedValidObjectType
,
keys
)
return
mockArgs
.
Get
(
0
)
.
([]
ValidObject
),
mockArgs
.
Error
(
1
)
}
func
(
mock
ManagerImplMock
)
CreateCompositeKey
(
objectType
string
,
attributes
[]
string
)
(
string
,
error
)
{
mockArgs
:=
mock
.
Called
(
objectType
,
attributes
)
return
mockArgs
.
Get
(
0
)
.
(
string
),
mockArgs
.
Error
(
1
)
}
func
(
mock
ManagerImplMock
)
SplitCompositeKey
(
compositeKey
string
)
(
string
,
[]
string
,
error
)
{
mockArgs
:=
mock
.
Called
(
compositeKey
)
return
mockArgs
.
Get
(
0
)
.
(
string
),
mockArgs
.
Get
(
1
)
.
([]
string
),
mockArgs
.
Error
(
2
)
}
func
(
mock
ManagerImplMock
)
InvokeChaincode
(
chaincodeName
string
,
args
[][]
byte
,
channel
string
)
pb
.
Response
{
mockArgs
:=
mock
.
Called
(
chaincodeName
,
args
,
channel
)
if
mockArgs
.
Get
(
0
)
==
nil
{
...
...
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/chaincode/model.go
View file @
ae71aee0
...
...
@@ -55,6 +55,31 @@ type StubInterfaceAdapter interface {
InvokeChaincode
(
chaincodeName
string
,
args
[][]
byte
,
channel
string
)
pb
.
Response
GetTxID
()
string
// CreateCompositeKey combines the given `attributes` to form a composite
// key. The objectType and attributes are expected to have only valid utf8
// strings and should not contain U+0000 (nil byte) and U+10FFFF
// (biggest and unallocated code point).
// The resulting composite key can be used as the key in PutState().
CreateCompositeKey
(
objectType
string
,
attributes
[]
string
)
(
string
,
error
)
// SplitCompositeKey splits the specified key into attributes on which the
// composite key was formed. Composite keys found during range queries
// or partial composite key queries can therefore be split into their
// composite parts.
SplitCompositeKey
(
compositeKey
string
)
(
string
,
[]
string
,
error
)
// GetStateByPartialCompositeKey queries the state in the ledger based on
// a given partial composite key. This function returns an iterator
// which can be used to iterate over all composite keys whose prefix matches
// the given partial composite key. The `objectType` and attributes are
// expected to have only valid utf8 strings and should not contain
// U+0000 (nil byte) and U+10FFFF (biggest and unallocated code point).
// See related functions SplitCompositeKey and CreateCompositeKey.
// Call Close() on the returned StateQueryIteratorInterface object when done.
// The query is re-executed during validation phase to ensure result set
// has not changed since transaction endorsement (phantom reads detected).
GetStateByPartialCompositeKey
(
objectType
string
,
keys
[]
string
)
(
shim
.
StateQueryIteratorInterface
,
error
)
}
type
ChaincodeParameter
struct
{
...
...
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/chaincode/valid_object.go
View file @
ae71aee0
...
...
@@ -6,4 +6,5 @@ type ValidObject interface {
CheckBeforeAdd
(
manager
IManager
)
error
CheckBeforeUpdate
(
updatedObject
ValidObject
,
manager
IManager
)
error
New
()
ValidObject
GetObjectType
()
string
}
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/invoke/keyValueCC.go
View file @
ae71aee0
...
...
@@ -18,4 +18,6 @@ const (
AddKeyValueArrayFunction
=
"addKeyValueArray"
GetKeyValueArrayFunction
=
"getKeyValueArray"
GetKeyValueArrayByPartOfKeyFunction
=
"getKeyValueArrayByPartOfKey"
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/accountCC/Account_data.go
View file @
ae71aee0
...
...
@@ -17,6 +17,10 @@ type Account struct {
CurrencyType
string
`json:"currency_type,omitempty"`
}
func
(
this
Account
)
GetObjectType
()
string
{
return
"Account"
;
}
func
(
this
Account
)
ToUserAccountInfo
()
*
UserAccountInfo
{
return
&
UserAccountInfo
{
UserID
:
this
.
UserID
,
...
...
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/accountCC/Wallet_data.go
View file @
ae71aee0
...
...
@@ -15,6 +15,10 @@ type Wallet struct {
Status
AccountStatus
`json:"status,omitempty"`
}
func
(
this
Wallet
)
GetObjectType
()
string
{
return
"Wallet"
;
}
func
(
this
Wallet
)
CheckBeforeAdd
(
manager
chaincode
.
IManager
)
error
{
// TODO check user exists
// TODO when add check AccountStatus_ACTIVE : wallet.Status = model.AccountStatus_ACTIVE
...
...
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/commissionCC/Commission_data.go
View file @
ae71aee0
...
...
@@ -18,6 +18,10 @@ type Commission struct {
CommissionPercent
float64
`json:"commission_percent,omitempty"`
}
func
(
this
Commission
)
GetObjectType
()
string
{
return
"Commission"
;
}
func
(
this
Commission
)
New
()
chaincode
.
ValidObject
{
return
&
Commission
{}
}
...
...
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/cryptocurrencyCC/CryptocurrencyStore_data.go
View file @
ae71aee0
...
...
@@ -19,6 +19,10 @@ type CryptocurrencyStore struct {
Amount
nums
.
PlainCurrencyNumber
`json:"amount"`
}
func
(
this
CryptocurrencyStore
)
GetObjectType
()
string
{
return
"CryptocurrencyStore"
;
}
func
(
this
CryptocurrencyStore
)
New
()
chaincode
.
ValidObject
{
return
&
CryptocurrencyStore
{}
}
...
...
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/marketCC/MarketTransaction_data.go
View file @
ae71aee0
...
...
@@ -12,6 +12,10 @@ type MarketTransaction struct {
*
transactionCC
.
TransactionRecord
}
func
(
this
MarketTransaction
)
GetObjectType
()
string
{
return
"MarketTransaction"
;
}
func
(
this
MarketTransaction
)
New
()
chaincode
.
ValidObject
{
return
&
MarketTransaction
{}
}
...
...
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/offerCC/OfferRequest_data.go
View file @
ae71aee0
...
...
@@ -18,6 +18,10 @@ type OfferRequest struct {
Properties
chaincode
.
Fields
`json:"properties,omitempty"`
}
func
(
this
OfferRequest
)
GetObjectType
()
string
{
return
"OfferRequest"
;
}
const
ExternalTransactionID
=
"external_transaction_id"
const
ExternalAccountID
=
"external_account_id"
const
ReplayedID
=
"replayed_id"
...
...
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/organizationCC/Organization_data.go
View file @
ae71aee0
...
...
@@ -16,6 +16,10 @@ type Organization struct {
Website
string
`json:"website,omitempty"`
}
func
(
this
Organization
)
GetObjectType
()
string
{
return
"Organization"
;
}
func
(
this
Organization
)
CheckBeforeAdd
(
manager
chaincode
.
IManager
)
error
{
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/preferenceCC/Preference_data.go
View file @
ae71aee0
...
...
@@ -12,6 +12,10 @@ type Preference struct {
Fields
chaincode
.
Fields
`json:"fields,omitempty"`
}
func
(
this
Preference
)
GetObjectType
()
string
{
return
"Preference"
;
}
func
(
this
Preference
)
CheckBeforeAdd
(
manager
chaincode
.
IManager
)
error
{
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/requests/Id_data.go
View file @
ae71aee0
...
...
@@ -14,12 +14,22 @@ type ArrayId struct {
ArrayId
[]
Id
`json:"array_id,omitempty"`
}
type
PartKey
struct
{
Keys
[]
string
`json:"keys,omitempty"`
}
func
UnmarshalArrayId
(
data
[]
byte
)
(
*
ArrayId
,
error
)
{
var
obj
ArrayId
err
:=
json
.
Unmarshal
(
data
,
&
obj
)
return
&
obj
,
err
;
}
func
UnmarshalPartKey
(
data
[]
byte
)
(
*
PartKey
,
error
)
{
var
obj
PartKey
err
:=
json
.
Unmarshal
(
data
,
&
obj
)
return
&
obj
,
err
;
}
func
(
this
Id
)
Validate
()
error
{
if
len
(
this
.
Id
)
==
0
{
return
errors
.
New
(
"Id is empty"
)
...
...
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/transactionCC/TransactionRecord_data.go
View file @
ae71aee0
...
...
@@ -31,6 +31,10 @@ type TransactionRecord struct {
InOutType
InputOutputType
`json:"input_output_type"`
}
func
(
this
TransactionRecord
)
GetObjectType
()
string
{
return
"TransactionRecord"
;
}
func
(
this
TransactionRecord
)
CheckBeforeAdd
(
manager
chaincode
.
IManager
)
error
{
// TODO добавить проверку в регуляторном канале передав this
// проверка статических переменных
...
...
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/userCC/User_data.go
View file @
ae71aee0
...
...
@@ -37,6 +37,10 @@ type User struct {
Roles
[]
actions
.
Roles
`json:"roles"`
// TODO уйдет в link_user
}
func
(
this
User
)
GetObjectType
()
string
{
return
"User"
;
}
func
(
this
User
)
CheckBeforeAdd
(
manager
chaincode
.
IManager
)
error
{
err
:=
VerifyPublicKey
(
manager
,
this
)
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/model/userPreferenceCC/UserPreference_data.go
View file @
ae71aee0
...
...
@@ -28,6 +28,10 @@ func (this UserPreference) CheckBeforeAdd(manager chaincode.IManager) error {
return
nil
}
func
(
this
UserPreference
)
GetObjectType
()
string
{
return
"UserPreference"
;
}
func
(
this
UserPreference
)
CheckBeforeUpdate
(
updatedObject
chaincode
.
ValidObject
,
manager
chaincode
.
IManager
)
error
{
return
this
.
CheckBeforeAdd
(
manager
)
}
...
...
This diff is collapsed.
Click to expand it.
vendor/gitlab.smartblocklab.com/smartcontracts/common/nums/currency.go
View file @
ae71aee0
...
...
@@ -22,6 +22,9 @@ var btg, _ = NewAsset("BTG", 8, "21000000", "0.00000001")
var
doge
,
_
=
NewAsset
(
"DOGE"
,
8
,
"21000000"
,
"0.00000001"
)
var
emc2
,
_
=
NewAsset
(
"EMC2"
,
8
,
"21000000"
,
"0.00000001"
)
var
rub
,
_
=
NewAsset
(
"RUB"
,
2
,
"2777530283277760"
,
"0.01"
)
var
usd
,
_
=
NewAsset
(
"USD"
,
2
,
"2777530283277760"
,
"0.01"
)
// TODO use channel for this
func
CurrencyTypeFrom
(
currencyType
string
)
(
*
Asset
,
error
)
{
if
len
(
currencyType
)
==
0
{
...
...
@@ -67,6 +70,10 @@ func CurrencyTypeFrom(currencyType string) (*Asset, error) {
return
doge
,
nil
case
"EMC2"
:
return
emc2
,
nil
case
"RUB"
:
return
rub
,
nil
case
"USD"
:
return
usd
,
nil
default
:
return
nil
,
logging
.
Get
()
.
Errorf
(
"failed. Bad currencyType %s"
,
currencyType
)
}
...
...
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help