@@ -43,3 +43,102 @@ export function validateAccountName(value) {
43
43
}
44
44
return null ;
45
45
}
46
+
47
+ export function voiceText ( wif , account , text , reply , share , beneficiaries , loop , callback ) {
48
+ reply = typeof reply === 'undefined' ?false :reply ;
49
+ share = typeof share === 'undefined' ?false :share ;
50
+ beneficiaries = typeof beneficiaries === 'undefined' ?false :beneficiaries ;
51
+ loop = typeof loop === 'undefined' ?false :loop ;
52
+ callback = typeof callback === 'undefined' ?function ( ) { } :callback ;
53
+
54
+ let use_previous = function ( wif , account , text , reply , share , beneficiaries , previous , callback ) {
55
+ let object = {
56
+ 'p' :previous ,
57
+ //'t':'t',//text as default type
58
+ 'd' :{
59
+ 't' :text ,
60
+ }
61
+ } ;
62
+ if ( reply ) {
63
+ object [ 'd' ] [ 'r' ] = reply ;
64
+ }
65
+ else { //share conflict with reply
66
+ if ( share ) {
67
+ object [ 'd' ] [ 's' ] = share ;
68
+ }
69
+ }
70
+ if ( beneficiaries ) { //json example: [{"account":"committee","weight":1000}]
71
+ object [ 'd' ] [ 'b' ] = beneficiaries ;
72
+ }
73
+ viz . broadcast . custom ( wif , [ ] , [ account ] , 'V' , JSON . stringify ( object ) , function ( err , result ) {
74
+ callback ( ! err ) ;
75
+ } ) ;
76
+ }
77
+ if ( false !== loop ) {
78
+ use_previous ( wif , account , text , reply , share , beneficiaries , loop , callback ) ;
79
+ }
80
+ else {
81
+ viz . api . getAccount ( account , 'V' , function ( err , result ) {
82
+ if ( ! err ) {
83
+ use_previous ( wif , account , text , reply , share , beneficiaries , result . custom_sequence_block_num , callback ) ;
84
+ }
85
+ else {
86
+ callback ( false ) ;
87
+ }
88
+ } ) ;
89
+ }
90
+ }
91
+
92
+ export function voicePublication ( wif , account , title , markdown , description , image , reply , share , beneficiaries , loop , callback ) {
93
+ description = typeof description === 'undefined' ?false :description ;
94
+ image = typeof image === 'undefined' ?false :image ;
95
+ reply = typeof reply === 'undefined' ?false :reply ;
96
+ share = typeof share === 'undefined' ?false :share ;
97
+ beneficiaries = typeof beneficiaries === 'undefined' ?false :beneficiaries ;
98
+ loop = typeof loop === 'undefined' ?false :loop ;
99
+ callback = typeof callback === 'undefined' ?function ( ) { } :callback ;
100
+
101
+ let use_previous = function ( wif , account , title , markdown , description , image , reply , share , beneficiaries , previous , callback ) {
102
+ let object = {
103
+ 'p' :previous ,
104
+ 't' :'p' , //text as default type
105
+ 'd' :{
106
+ 't' :title ,
107
+ 'm' :markdown ,
108
+ }
109
+ } ;
110
+ if ( description ) {
111
+ object [ 'd' ] [ 'd' ] = description ;
112
+ }
113
+ if ( image ) {
114
+ object [ 'd' ] [ 'i' ] = image ;
115
+ }
116
+ if ( reply ) {
117
+ object [ 'd' ] [ 'r' ] = reply ;
118
+ }
119
+ else { //share conflict with reply
120
+ if ( share ) {
121
+ object [ 'd' ] [ 's' ] = share ;
122
+ }
123
+ }
124
+ if ( beneficiaries ) { //json example: [{"account":"committee","weight":1000}]
125
+ object [ 'd' ] [ 'b' ] = beneficiaries ;
126
+ }
127
+ viz . broadcast . custom ( wif , [ ] , [ account ] , 'V' , JSON . stringify ( object ) , function ( err , result ) {
128
+ callback ( ! err ) ;
129
+ } ) ;
130
+ }
131
+ if ( false !== loop ) {
132
+ use_previous ( wif , account , title , markdown , description , image , reply , share , beneficiaries , loop , callback ) ;
133
+ }
134
+ else {
135
+ viz . api . getAccount ( account , 'V' , function ( err , result ) {
136
+ if ( ! err ) {
137
+ use_previous ( wif , account , title , markdown , description , image , reply , share , beneficiaries , result . custom_sequence_block_num , callback ) ;
138
+ }
139
+ else {
140
+ callback ( false ) ;
141
+ }
142
+ } ) ;
143
+ }
144
+ }
0 commit comments